Playing Cards Arrays
Author |
Message |
Naveg
|
Posted: Sun Mar 20, 2005 8:34 pm Post subject: Playing Cards Arrays |
|
|
For making a playing card game, would it be best to have an array 1..52 of cards, or a two dimensional array 1..4,1..14 of cards??
perhaps i could make a type called card with values suit and number, and then make an array of type card?? which way is best? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 8:38 pm Post subject: (No subject) |
|
|
i think a 2d array would be best and if you wanted to, you could make variables so you dont have to remmeber the corisponding number |
|
|
|
|
|
Naveg
|
Posted: Sun Mar 20, 2005 8:43 pm Post subject: (No subject) |
|
|
Bacchus wrote: i think a 2d array would be best and if you wanted to, you could make variables so you dont have to remmeber the corisponding number
what exactly do you mean? i'll be using BMP images for all the cards. They're numbered like d5, c14 etc...(diamond 5, club king) |
|
|
|
|
|
Bacchus
|
|
|
|
|
Naveg
|
Posted: Sun Mar 20, 2005 9:21 pm Post subject: (No subject) |
|
|
ok i got that down, and i assigned the pictures to the array. but now, when i use Pic.Draw to show a card, it cuts off like the top quarter of the image. The image is fine on its own.
an example:
code: |
Pic.Draw(deck(3,11),50,50,picCopy) |
|
|
|
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 10:37 pm Post subject: (No subject) |
|
|
hmm... |
|
|
|
|
|
Cervantes
|
Posted: Sun Mar 20, 2005 10:41 pm Post subject: (No subject) |
|
|
cut the spam, Pwned. -10 bits |
|
|
|
|
|
jamonathin
|
Posted: Wed Mar 23, 2005 7:03 am Post subject: (No subject) |
|
|
that's a really good idea, gj bacchus, ima use that for my game |
|
|
|
|
|
Sponsor Sponsor
|
|
|
zylum
|
Posted: Wed Mar 23, 2005 4:08 pm Post subject: (No subject) |
|
|
a better idea is to make a record... i mean, how would you go about shuffling a deck in a 2d array? i mean you could but its much harder.
records are much easier to read and easier to program with. here's what the code looks like (i've also included an initialize procedure and shuffle procedure)
code: | type CardData :
record
face : string
value : int
end record
proc InitializeDeck (var cards : array 1 .. 52 of CardData)
for i : 0 .. 51
cards (i + 1).value := i mod 13 + 1
if i div 13 = 0 then
cards (i + 1).face := "Diamods"
elsif i div 13 = 1 then
cards (i + 1).face := "Clubs"
elsif i div 13 = 2 then
cards (i + 1).face := "Hearts"
elsif i div 13 = 3 then
cards (i + 1).face := "Spades"
end if
end for
end InitializeDeck
proc ShuffleDeck (var cards : array 1 .. 52 of CardData)
var tempValue : int
var tempFace : string
var idx : int
for i : 1 .. 52
idx := Rand.Int (1, 52)
tempValue := cards (i).value
tempFace := cards (i).face
cards (i).value := cards (idx).value
cards (i).face := cards (idx).face
cards (idx).value := tempValue
cards (idx).face := tempFace
end for
end ShuffleDeck
var Cards : array 1 .. 52 of CardData
InitializeDeck (Cards)
ShuffleDeck (Cards)
for i : 1 .. 52
put Cards (i).value, " of ", Cards (i).face
end for |
|
|
|
|
|
|
GlobeTrotter
|
Posted: Wed Mar 30, 2005 10:35 pm Post subject: (No subject) |
|
|
zylum wrote:
code: |
proc ShuffleDeck (var cards : array 1 .. 52 of CardData)
var tempValue : int
var tempFace : string
var idx : int
for i : 1 .. 52
idx := Rand.Int (1, 52)
tempValue := cards (i).value
tempFace := cards (i).face
cards (i).value := cards (idx).value
cards (i).face := cards (idx).face
end for
end ShuffleDeck
|
That doesn't make sense. First of all, what is the point in the temp vars, second of all, it gives you repeats. |
|
|
|
|
|
StarGateSG-1
|
Posted: Thu Mar 31, 2005 8:35 am Post subject: (No subject) |
|
|
First off, you need temp variables to store the data when you pass it out of the procedure, otherwise it will get messy if you have to use the real variable as a temp and real value. Secondly, Of course it gives you doubles that is a shuffler not a dealer. |
|
|
|
|
|
Martin
|
Posted: Thu Mar 31, 2005 9:02 am Post subject: (No subject) |
|
|
Bacchus wrote: well 1st off, kings arnt 14, they're 13 and wat you can do is just to make it easier to read.. though it would add more variables
code: | var dimond:=1
var spade:=2
var heart:=3
var club:=4
%im putting in that order for this
var cards:array 1..4,1..14 of it | then to get a certain card:
cards(club,13)
since club =4 it would be:
cards(4,13)
thats it just to avoid some confusion, preference really and if you can remember which suit is which num lol
I'm assuming that the value of spade will never change, so make it a constant. Also, use caps to indicated that it's a constant.
|
|
|
|
|
|
zylum
|
Posted: Thu Mar 31, 2005 9:24 am Post subject: (No subject) |
|
|
my bad, code fixed.. forgot to reassign the the temp vars to the actual arrays. |
|
|
|
|
|
GlobeTrotter
|
Posted: Thu Mar 31, 2005 9:49 pm Post subject: (No subject) |
|
|
StarGateSG-1 wrote: First off, you need temp variables to store the data when you pass it out of the procedure, otherwise it will get messy if you have to use the real variable as a temp and real value. Secondly, Of course it gives you doubles that is a shuffler not a dealer.
Call me crazy, but that makes absolutely no sense to me at all. First of all, I didn't mention real variables at all. Second of all, a shuffler should not repeat, under any circumstances. |
|
|
|
|
|
zylum
|
Posted: Fri Apr 01, 2005 1:36 am Post subject: (No subject) |
|
|
ok guys calm down. problem fixed, no repeats in the shuffler, it was a small error. lets get on with our lives |
|
|
|
|
|
|
|