Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Strict
- import mojo
- Global myGame:MyGame
- Global Suits:String[] = ["clubs", "diamonds", "hearts", "spades"]
- Function Main:int()
- myGame = new MyGame
- return 0
- End Function
- Class MyGame extends App
- Field deck:Holder
- Method OnCreate:Int()
- deck = New Holder
- SetUpdateRate 60
- return 0
- End Method
- Method OnLoading:Int()
- return 0
- End Method
- Method OnUpdate:Int()
- return 0
- End Method
- Method OnRender:Int()
- Cls
- deck.draw()
- return 0
- End Method
- end class
- Class Holder
- Field cardList:LinkedList<Card>
- Method new()
- cardList = New LinkedList<Card>
- Local c:Card
- Local pos% = 0
- Local s% = 0
- For Local Suit:String = Eachin Suits
- For Local n% = 0 to 12
- c = New Card(Suit, n + 1, pos)
- c.x = n * 50
- c.y = s * 100
- self.cardList.AddLast(c)
- pos+=1
- Next
- s+=1
- Next
- shuffle()
- End
- Method shuffle:Void()
- Local randSize:Int = Self.cardList.Count() * 2
- For Local c:Card = EachIn cardList
- c.shuffleOrder = Rnd(randSize)
- Next
- ' Sort stack here!!!
- End Method
- Method draw:Void()
- For Local c:Card = EachIn cardList
- c.draw()
- Next
- End
- End
- Class Card
- Field value%
- Field suit:String
- Field shuffleOrder%
- Field x#, y#
- Method new(suit:String, value:Int, shuffleOrder:Int)
- self.suit = suit
- self.value = value
- self.shuffleOrder = shuffleOrder
- End
- Method draw:Void()
- DrawText Self.suit, x, y
- DrawText Self.value, x, y+12
- End
- End
- Class LinkedList<T>
- Method Equals:Object( lhs:Object,rhs:Object )
- Return lhs=rhs
- End
- Method Clear:Void()
- _head=New LinkedNode<T>()
- End
- Method Count:Int()
- Local n:Int
- local node:=_head._succ
- While node<>_head
- node=node._succ
- n+=1
- Wend
- Return n
- End
- Method IsEmpty?()
- Return _head._succ=_head
- End
- Method First:T()
- Return _head._succ._data
- End
- Method Last:T()
- Return _head._pred._data
- End
- Method AddFirst:LinkedNode<T>( data:T )
- Return New LinkedNode<T>( _head._succ,_head,data )
- End
- Method AddLast:LinkedNode<T>( data:T )
- Return New LinkedNode<T>( _head,_head._pred,data )
- End
- 'I think this should GO!
- Method Remove:Void( value:T )
- RemoveEach value
- End
- Method RemoveEach:Void( value:T )
- Local node:=_head._succ
- While node<>_head
- node=node._succ
- If Equals( node._pred._data,value ) node._pred.Remove
- Wend
- End
- Method RemoveFirst:T()
- Local data:T=_head._succ._data
- _head._succ.Remove
- Return data
- End
- Method RemoveLast:T()
- Local data:T=_head._pred._data
- _head._pred.Remove
- Return data
- End
- Method ObjectEnumerator:LinkedEnumerator<T>()
- Return New LinkedEnumerator<T>( Self )
- End Method
- Field _head:=New LinkedNode<T>
- End
- Class LinkedEnumerator<T>
- Method New( list:LinkedList<T> )
- _list=list
- _curr=list._head._succ
- End Method
- Method HasNext:Bool()
- Return _curr<>_list._head
- End
- Method NextObject:T()
- Local data:T=_curr._data
- _curr=_curr._succ
- Return data
- End
- Field _list:LinkedList<T>
- Field _curr:LinkedNode<T>
- End
- Class LinkedNode<T>
- 'create a _head node
- Method New()
- _succ=Self
- _pred=Self
- End
- 'create a link node
- Method New( succ:LinkedNode,pred:LinkedNode,data:T )
- _succ=succ
- _pred=pred
- _succ._pred=Self
- _pred._succ=Self
- _data=data
- End
- Method Value:T()
- Return _data
- End
- Method Remove:Void()
- _succ._pred=_pred
- _pred._succ=_succ
- End Method
- Field _succ:LinkedNode
- Field _pred:LinkedNode
- Field _data:T
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement