'ello, I've created functions that animate the deck being assembled and that deal out the cards. I need a function that will assign each of my 52 card objects an identity of one of the 14 card types: 2,3,4...10,jack,queen,king,ace,joker. I've tried to make a function (its' the long one called CardAssign() at the bottom), it generates a random number from a range of 14 numbers (0 thru 13) and assigns the card whatever identity the case gives it. I've added counters to each case so that i can stop the function from making more than 4 types of each card but i don't know how to stop it from doing so. Any ideas? Here's my code:
`setup camera
make camera 1
position camera 1, 500, -1000, -1000 `plain is facing toward monitor, so alter z instead of y for raised camera
point camera 1, 500, 0, 1000
`create data type for array
type CardInfo
joker as boolean
ace as boolean
king as boolean
queen as boolean
jack as boolean
ten as boolean
nine as boolean
eight as boolean
seven as boolean
six as boolean
five as boolean
four as boolean
three as boolean
two as boolean
FaceDown as boolean
FaceUp as boolean
ObjectNumber as integer
CardXPos as integer
CardYPos as integer
endtype
`create array to hold card info
dim Deck(52) as CardInfo
`setup basic card info
data 0,0, 125,0, 250,0, 375,0, 500,0, 625,0, 750,0, 875,0, 1000,0,
data 0,-175, 125,-175, 250,-175, 375,-175, 500,-175, 625,-175, 750,-175, 875,-175, 1000,-175,
data 0,-350, 125,-350, 250,-350, 375,-350, 500,-350, 625,-350, 750,-350, 875,-350, 1000,-350,
data 0,-525, 125,-525, 250,-525, 375,-525, 500,-525, 625,-525, 750,-525, 875,-525, 1000,-525,
data 0,-700, 125,-700, 250,-700, 375,-700, 500,-700, 625,-700, 750,-700, 875,-700, 1000,-700,
data 0,-875, 125,-875, 250,-875, 375,-875, 500,-875, 625,-875, 750,-875, 875,-875, 1000,-875,
data 0,-1050, 125,-1050, 250,-1050, 375,-1050, 500,-1050, 625,-1050, 750,-1050
for z = 1 to 52
Deck(z).ObjectNumber = z
read Deck(z).CardXPos
read Deck(z).CardYPos
next z
`make cards and put deck on screen
MakeDeck()
Deal()
`CardAssign()
`********************************************************MAIN LOOP***********************************************************
while escapekey() <> 1
endwhile
`*****************************************************END OF MAIN LOOP********************************************************
`------------------------------------------------------END OF PROGRAM--------------------------------------------------------
`---------------------------------------------------------FUNCTIONS----------------------------------------------------------
FUNCTION MakeDeck()`draws the deck onscreen
LastCardPos = 0
for a = 52 to 1 step -1
FallHeight = -120
make object box a, 100, 150, 1
color object a, rgb(rnd(255),rnd(255),rnd(255))
`make animation for deck being built
for b = 1 to 5
position object a, 0, 200, FallHeight `y pos is 200 so that deck will sit beyond card dealing area
FallHeight = FallHeight + 20
wait 1
next b
position object a, 0, 200, LastCardPos
LastCardPos = LastCardPos - 1
next a
ENDFUNCTION
FUNCTION Deal()`deals the cards out onscreen
for a = 1 to 52
position object a, Deck(a).CardXPos, Deck(a).CardYPos, 1
wait 30
next a
ENDFUNCTION
FUNCTION CardAssign() `dictates which objects are which cards
for a = 1 to 52
b = rnd(13)
select b
case 0:
Deck(a).two = 1
if twocard >= 5
CardAssign()
endif
twocard = twocard + 1
endcase
case 1:
Deck(a).three = 1
if threecard >= 5
CardAssign()
endif
threecard = threecard + 1
endcase
case 2:
Deck(a).four = 1
if fourcard >= 5
CardAssign()
endif
fourcard = fourcard + 1
endcase
case 3:
Deck(a).five = 1
if fivecard >= 5
CardAssign()
endif
fivecard = fivecard + 1
endcase
case 4:
Deck(a).six = 1
if sixcard >= 5
CardAssign()
endif
sixcard = sixcard + 1
endcase
case 5:
Deck(a).seven = 1
if sevencard >= 5
CardAssign()
endif
sevencard = sevencard + 1
endcase
case 6:
Deck(a).eight = 1
if eightcard >= 5
CardAssign()
endif
eightcard = eightcard + 1
endcase
case 7:
Deck(a).nine = 1
if ninecard >= 5
CardAssign()
endif
ninecard = ninecard + 1
endcase
case 8:
Deck(a).ten = 1
if tencard >= 5
CardAssign()
endif
tencard = tencard + 1
endcase
case 9:
Deck(a).jack = 1
if jackcard >= 5
CardAssign()
endif
jackcard = jackcard + 1
endcase
case 10:
Deck(a).queen = 1
if queencard >= 5
CardAssign()
endif
queencard = queencard + 1
endcase
case 11:
Deck(a).king = 1
if kingcard >= 5
CardAssign()
endif
kingcard = kingcard + 1
endcase
case 12:
Deck(a).ace = 1
if acecard >= 5
CardAssign()
endif
acecard = acecard + 1
endcase
case 13:
Deck(a).joker = 1
if jokercard >= 5
CardAssign()
endif
jokercard = jokercard + 1
endcase
case default: print "Error: program malfunction."
endcase
endselect
next a
ENDFUNCTION
Was wondering, would it be better to do it the way im doing it or set the identities of the cards first, then find a way to randomly deal them out? thx for your help
DBPro User
PC: WinXP, AthlonXP 2100+ 1.7ghz, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mn DDR400 system RAM. Thank you for your help.