Dealing out cards

BlitzMax Forums/BlitzMax Programming/Dealing out cards

z80jim(Posted 2008) [#1]
I have been using blitzmax for years, though I haven't taken great steps to learn it, I'm only now getting into GUI, and one particular problem has been bothering me. I can't seem to get the darn thing to deal out a deck of cards!

here's my most successful attempt, though it still won't work properly and I'm stumped. Can anyone help?



SeedRnd MilliSecs()

Global dealnum:Int
Global dealsuit:Int
Global dealtnum:Int[13]
Global dealtsuit:Int[4]
Global finalnum:String[13]
Global finalsuit:String[4]
Global cardnumber:Int[13]
Global cardsuit:Int[4]
Global deal:Int
Global dealdeal:Int
Global dealer:Int
Graphics 640,480'not neccessary for now, only feedback is through print commands.

While Not KeyHit(key_q)'mean loop, doesn't do anything yet
deala
'display
End
Wend

Function printatize()
If dealtsuit[c]=0
finalsuit[c]="Hearts"
EndIf
If dealtsuit[c]=1
finalsuit[c]="Diamonds"
EndIf
If dealtsuit[c]=2
finalsuit[c]="Clubs"
EndIf
If dealtsuit[c]=3
finalsuit[c]="Spades"
EndIf
If dealtsuit[c]=3
finalsuit[c]="Spades"
EndIf


'... and numbers
If dealtnum[i]=0
finalnum[i]="Two"
EndIf
If dealtnum[i]=1
finalnum[i]="Three"
EndIf
If dealtnum[i]=2
finalnum[i]="Four"
EndIf
If dealtnum[i]=3
finalnum[i]="Five"
EndIf
If dealtnum[i]=4
finalnum[i]="Six"
EndIf
If dealtnum[i]=5
finalnum[i]="Seven"
EndIf
If dealtnum[i]=6
finalnum[i]="Eight"
EndIf
If dealtnum[i]=7
finalnum[i]="Nine"
EndIf
If dealtnum[i]=8
finalnum[i]="Ten"
EndIf
If dealtnum[i]=9
finalnum[i]="Jack"
EndIf
If dealtnum[i]=10
finalnum[i]="Queen"
EndIf
If dealtnum[i]=11
finalnum[i]="King"
EndIf
If dealtnum[i]=12
finalnum[i]="Ace"
EndIf
End Function

Function deala()
For dealnum=0 To 12
For dealsuit=0 To 3
Cls
deal=Rnd(0,12)
dealtnum[deal]=dealnum
deal=Rnd(0,3)
dealtsuit[deal]=dealsuit
DrawText dealnum,1,1
printatize
Print finalnum[i]+" of "+finalsuit[c]
Flip
Next
Next
End Function

Function display()
For i=0 To 12
For c=0 To 3
printatize
Print finalnum[i]+" of "+finalsuit[c]
Next
Next
EndFunction


TwoCorin517(Posted 2008) [#2]
This doesn't quite work, but I hope it inspires you.



z80jim(Posted 2008) [#3]
might I ask why it doesn't work though? It seemed to run just fine, it fixed the problems I was having lol.
You've used a lot of stuff that I'm only slightly familiar with... can you please please please add notes so I know what's doing what? Thanks a million for replying! I'm specifically only slightly knowledgeable on the topic of types... I used to kinda know how to do a simple one, but I forgot lol.


Perturbatio(Posted 2008) [#4]
Here's mine, I would've finished it about two hours ago if I wasn't watching TV at the same time :)



TwoCorin517(Posted 2008) [#5]
Sorry for the slow reply earlier, I was 4 hrs. late, but as my excuse, I live in the real world, and I had to write the code from scratch.

It works for the most part, but I thought I saw a repeat once. But I haven't seen it for a bit, so it might be ok.

First if you plan on doing much of anything with BlitzMax I'd suggest you get familiar with types. I'll see what I can do about adding comments.

Types are basically a way to organize information. Theoretically you can write programs without them, but it makes your job ALOT easier. Like arrays they organize information under a single name. Int and Stream are types, they're just preset and you don't have to declare them the same way in arrays.

Methods are like fields, except they're functions within the type.

When I created the TCard Type, every instance of the TCard set will have a String Variable named Suit, and a String Variable named Face.

Think of each type as a Templete, within each Templete it has preset Variables, so every Instance of the type/templete will have the variables declared in the type. You've used types before whether you know it or not.

I didn't comment on the setting Ace-King or Spades - Diamonds as i figured you'd figure it out.



This way in order to make a traditional Card Deck, all you have to do is:
NewDeck:TDeck
NewDeck.Create()
NewDeck.Set()

And its all ready to be used, then to shuffle it, you do:
NewDeck.Shuffle()


The reason I make you Set and Shuffle is you may not want that, with a little more work, and merging with Perturbatio's this could work for most decks. Like you could have another method that would be, "SetPokerDeck()" or something like that I think.


z80jim(Posted 2008) [#6]
wow thanks both of you :) I wasn't expecting people to write code from scratch thanks a million!
I'm still reading through your comments Corin, but it seems to be very well documented now I'll fiddle around with it to see what I can mess with now :D


TwoCorin517(Posted 2008) [#7]
Your welcome, Good, these are important concepts, some I overuse, but important none the less. :D

It was a good chance to flex my programming muscles anyway. :D


z80jim(Posted 2008) [#8]
you're gonna get sick of me lol I'm sure I'll have more questions for you before we're through with this :P


TwoCorin517(Posted 2008) [#9]
I doubt it, however I suggest checking out talk.christiandevs.com That's where I hang out alot, is not just Christians, but there's a great community if I do say so myself, and a couple BM users.