Working on my first monkey app
Monkey Forums/Monkey Programming/Working on my first monkey app
| ||
| I am wanting to write a card game, I am trying to port the card game 'For sale' and have gotten the models and data set up but I am stuck on 3 areas. 1) Shuffling the cards 2) Intro Scene -> Player creation -> Play loop 3) Drawing and animating cards Ideally, I'd like to add GameKit/GameCenter so that you could have multiple people playing the card game on a turn-based game. But its something I have no experience with. The code I have so far seems to be working, but this is my first attempt so it might be wrong. I am happy for code-reviews. At the moment, all this does is setup the cards/data. But it does not draw anything on to the screen. I have a series of basic graphics I'd like to use for the cards but have never done anything using images with Monkey yet. Anyway, my code is below
' Port of For Sale card game for Monkey
' First attempt at Monkey app
' ---------------------------------
Import mojo.app
Import mojo.graphics
Const kMaxPlayers = 6
' Game States
Const kGameStateSetup:Int = 0
Const kGameStateInPlay:Int = 1
Const kGameStateIsPaused:int = 2
Global gameState:Int = kGameStateSetup
Global cards:List <fsCard> = New List <fsCard>
Global propertyCards:List <fsProperty> = New List<fsProperty>
Global chequeCards:List <fsCheque> = New List<fsCheque>
Global players:= New List<fsPlayer>
' ----------------
' Main method
' ----------------
Function Main()
New Game
End
' ----------
' Classes
' ----------
Class fsPlayer
Field name:String
Field coins:Int
'Field cards:List <fsCard>
Method New(name:String)
Self.name = name
Self.coins = 14
End
End
Class fsCard
Field value:Int
Field status:Int
Method New (value:Int=0)
Self.value = value
Self.status = 0
End
End
Class fsProperty Extends fsCard
Field name:String
Method New (name:String="", value:Int=0)
Self.name = name
Self.value = value
End
Method Render()
PushMatrix()
Print "Property card: " + Self.name + " " + Self.value
PopMatrix()
End
End
Class fsCheque Extends fsCard
Method New(value:Int=0)
Self.value = value
End
Method Render()
PushMatrix()
Print "Cheque card: " + Self.value
PopMatrix()
End
End
Class Game Extends App
Method OnCreate()
gameState = kGameStateSetup
Self.createPropertyCards()
Self.createChequeCards()
SetUpdateRate(60)
End
Method OnRender()
Local sizeOfPropertyCards:Int = propertyCards.Count()
Local sizeOfChequeCards:Int = chequeCards.Count()
Cls(0, 42, 0)
SetColor(200, 200, 200)
DrawText "For sale",0,0
DrawText "# of Property cards = " + sizeOfPropertyCards, 100, 100
DrawText "Number of Cheque cards = " + sizeOfChequeCards, 100, 125
#Rem
For Local c:= Eachin propertyCards
c.Render()
Next
For Local c:= Eachin chequeCards
c.Render()
End
#End
End
' Create cards -------------------------------------------------
Method createPropertyCards()
propertyCards.AddLast( New fsProperty("Cardboard box",1) )
propertyCards.AddLast( New fsProperty("Outhouse", 2) )
propertyCards.AddLast( New fsProperty("Sewer", 3) )
propertyCards.AddLast( New fsProperty("Dog house", 4) )
propertyCards.AddLast( New fsProperty("Cave", 5) )
propertyCards.AddLast( New fsProperty("Tepee", 6) )
propertyCards.AddLast( New fsProperty("Tent", 7) )
propertyCards.AddLast( New fsProperty("Igloo", 8) )
propertyCards.AddLast( New fsProperty("Beach hut", 9) )
propertyCards.AddLast( New fsProperty("Forest hut", 10) )
propertyCards.AddLast( New fsProperty("Tree house", 11) )
propertyCards.AddLast( New fsProperty("Highland house", 12) )
propertyCards.AddLast( New fsProperty("Camper van ", 13) )
propertyCards.AddLast( New fsProperty("Small island", 14) )
propertyCards.AddLast( New fsProperty("Wood house", 15) )
propertyCards.AddLast( New fsProperty("Lighthouse", 16) )
propertyCards.AddLast( New fsProperty("Barge boat", 17) )
propertyCards.AddLast( New fsProperty("RV", 18) )
propertyCards.AddLast( New fsProperty("Flat", 19) )
propertyCards.AddLast( New fsProperty("Thin house", 20) )
propertyCards.AddLast( New fsProperty("Residential house", 21) )
propertyCards.AddLast( New fsProperty("Large residential house", 22) )
propertyCards.AddLast( New fsProperty("1900 residential house", 23) )
propertyCards.AddLast( New fsProperty("Beach house", 24) )
propertyCards.AddLast( New fsProperty("Country estate", 25) )
propertyCards.AddLast( New fsProperty("Castle", 26) )
propertyCards.AddLast( New fsProperty("Manor House ", 27) )
propertyCards.AddLast( New fsProperty("Palace", 28) )
propertyCards.AddLast( New fsProperty("Penthouse apartment", 29) )
propertyCards.AddLast( New fsProperty("Space station", 30) )
End
Method createChequeCards()
For Local sets:Int = 0 To 1
For Local i:Int = 0 To 15
If (i = 1) Then
' Ignore it. No 1 value cards are created
Else
chequeCards.AddLast( New fsCheque(i) )
End If
Next
Next
End
End
|