'ello. My match cards game is coming along, but I'm having a problem with the Shuffle() function. It will shuffle the data on the cards but not in the way that I want. I have the cards color coded (no textures) for the time being so I can identify which cards are which and even after shuffling the colors of the cards will have changed but the cards themselves will be in the same spot. It's hard to explain and harder to understand i suspect lol, so here's the code:
`setup camera
make camera 1
position camera 1, 500, -1000, -1000
point camera 1, 500, 0, 1000
`create data type for array
type CardInfo
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
AlreadyMatched as boolean `use to check if card has already been matched
FaceDown as boolean `use to check if card is face down
FaceUp as boolean `use to check if card is face up
Suit as integer `use to check what suit card is for texturing
CardXPos as integer `card's x position
CardYPos as integer `card's y position
endtype
`create arrays
dim Deck(52) as CardInfo `deck
dim FirstCard(1) as CardInfo `first clicked card info holder variable for match detecion
dim SecondCard(1) as CardInfo `second clicked card info holder variable for match detecion
dim Card(1) as CardInfo `function parameter being passed to match detection function
dim Shuffler(1) as CardInfo `variable to hold data during shuffle function
global NumberOfCardsFlipped = 0 `keeps track of how many cards have been flipped over
global FirstCardClicked `1st card clicked, info to be passed to card flipping and match detecting function
global SecondCardClicked `2nd card clicked, info to be passed to card flipping and match detecting function
global CardsToBeMatched `keeps track of how many cards have been passed to match detecting function
global FirstCard `holds info for 1st card sent to match detecting function
global SecondCard `holds info for 2nd card sent to match detecting function
`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
read Deck(z).CardXPos
read Deck(z).CardYPos
Deck(z).FaceDown = 1
Deck(z).FaceUp = 0
Deck(z.)AlreadyMatched = 0
next z
`make cards and put deck on screen
MakeDeck()
CardAssign()
Shuffle()
Deal()
`********************************************************MAIN LOOP***********************************************************
while escapekey() <> 1 `hit Escape to exit game
MouseControl()
endwhile
`*****************************************************END OF MAIN LOOP********************************************************
`------------------------------------------------------END OF PROGRAM--------------------------------------------------------
`---------------------------------------------------------FUNCTIONS----------------------------------------------------------
FUNCTION MakeDeck()`draws the deck onscreen
LastCardPos = 0 `keeps track of z value of card in deck
for a = 52 to 1 step -1
FallHeight = -120
make object box a, 100, 130, 0
color object a, rgb(rnd(255),rnd(255),rnd(255)) `will replace with texture command
`make animation for cards falling onto deck
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 `these 2 lines place cards slightly above each other
LastCardPos = LastCardPos - 1 `creating the appearance of a stack of cards
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 Shuffle() `randomizes the card data
randomize timer()
for n = 1 to 5000
card1 = rnd(51) + 1
card2 = rnd(51) + 1
if card1 = card2 `make sure each of the 52 cards are represented by making sure that the 2 variables that
while card1 = card2 `store the random object numbers are not the same
card1 = rnd(51) + 1
card2 = rnd(51) + 1
endwhile
endif
Shuffler(1) = Deck(card1)
Deck(card1) = Deck(card2)
Deck(card2) = Shuffler(1)
next n
ENDFUNCTION
FUNCTION FlipFirstCardUp(WhichCardOne) `flips the first card over that is clicked
if Deck(WhichCardOne).AlreadyMatched = 1 `if the card has already been matched don't continue trying to match it again
exitfunction
endif
if Deck(WhichCardOne).FaceUp = 0 and Deck(WhichCardOne).FaceDown = 1 `if card is face down, set its values to face up
Deck(WhichCardOne).FaceDown = 0
Deck(WhichCardOne).FaceUp = 1
else
for ErrorMessage = 1 to 70 `if its already face up, give error message
text (screen width() - ((Screen width()/10) * 9)), (screen height() - ((Screen height()/10) * 9)), "That card has already been turned over. Please try another card."
wait 1
next ErrorMessage
exitfunction
endif
for MoveUp = 1 to 5 `if card is being set to face up, animate the card flipping over and being tilted
move object up WhichCardOne, 6 `toward the player
wait 10
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCardOne, 18
wait 10
next TwistLeft
for PitchDown = 1 to 5
pitch object down WhichCardOne, 6
wait 10
next PitchDown
wait 1500 `short delay for card to face toward player
for PitchUp = 1 to 5
pitch object up WhichCardOne, 6
wait 10
next PitchUp
for MoveDown = 1 to 5
move object down WhichCardOne, 6
wait 10
next MoveDown
MatchDetector(WhichCardOne) `send the first card's data to match detection functino
ENDFUNCTION
FUNCTION FlipSecondCardUp(WhichCardTwo) `flips 2nd card over that is flipped
if Deck(WhichCardTwo).AlreadyMatched = 1 `same as function above
exitfunction
endif
if Deck(WhichCardTwo).FaceUp = 0 and Deck(WhichCardTwo).FaceDown = 1 `same as function above
Deck(WhichCardTwo).FaceDown = 0
Deck(WhichCardTwo).FaceUp = 1
else
for ErrorMessage = 1 to 70 `same as function above
text (screen width() - ((Screen width()/10) * 9)), (screen height() - ((Screen height()/10) * 9)), "That card has already been turned over. Please try another card."
wait 1
next ErrorMessage
exitfunction
endif
for MoveUp = 1 to 5 `same as function above
move object up WhichCardTwo, 6
wait 10
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCardTwo, 18
wait 10
next TwistLeft
for PitchDown = 1 to 5
pitch object down WhichCardTwo, 6
wait 10
next PitchDown
wait 1500
for PitchUp = 1 to 5
pitch object up WhichCardTwo, 6
wait 10
next PitchUp
for MoveDown = 1 to 5
move object down WhichCardTwo, 6
wait 10
next MoveDown
MatchDetector(WhichCardTwo) `sends 2nd card's data to match detection function
ENDFUNCTION
FUNCTION FlipCardDown(WhichCard) `turns card back over
for MoveUp = 1 to 5
move object up WhichCard, 6
wait 10
next MoveUp
for TwistLeft = 1 to 10
turn object left WhichCard, 18
wait 10
next TwistLeft
for MoveDown = 1 to 5
move object down WhichCard, 6
wait 10
next MoveDown
Deck(WhichCard).FaceDown = 1 `sets card data back to face down
Deck(WhichCard).FaceUp = 0
ENDFUNCTION
FUNCTION MouseControl() `let player use mouse to interact with cards
if MouseClick() = 1 `if mouse is clicked
NumberOfCardsFlipped = NumberOfCardsFlipped + 1 `increment how many cards have been clicked so far
if NumberOfCardsFlipped = 1
FirstCardClicked = pick object (mousex(), mousey(),1,52) `if 1, send that card data to card flipper
FlipFirstCardUp(FirstCardClicked)
exitfunction
else
if NumberOfCardsFlipped = 2
SecondCardClicked = pick object (mousex(), mousey(),1,52) `if 2 send 2nd card data to card flipper
FlipSecondCardUp(SecondCardClicked)
NumberOfCardsFlipped = 0 `set # of cards clicked back to 0 for next match test
endif
endif
endif
ENDFUNCTION
FUNCTION MatchDetector(Card) `checks to see if 2 clicked cards match
CardsToBeMatched = CardsToBeMatched + 1 `increment how many cards have been sent to function so far
if CardsToBeMatched = 1
FirstCard = Card `if 1, save data for first card clicked and exit the function
exitfunction
endif
if CardsToBeMatched = 2 `if 2, save data for 2nd card and compare them using commands below
SecondCard = Card `if their data is the same, set them as matched and make them invisible
if Deck(FirstCard).two = 1 and Deck(SecondCard).two = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).three = 1 and Deck(SecondCard).three = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).four = 1 and Deck(SecondCard).four = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).five = 1 and Deck(SecondCard).five = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).six = 1 and Deck(SecondCard).six = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).seven = 1 and Deck(SecondCard).seven = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).eight = 1 and Deck(SecondCard).eight = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).nine = 1 and Deck(SecondCard).nine = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).ten = 1 and Deck(SecondCard).ten = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).jack = 1 and Deck(SecondCard).jack = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).queen = 1 and Deck(SecondCard).queen = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).king = 1 and Deck(SecondCard).king = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
if Deck(FirstCard).ace = 1 and Deck(SecondCard).ace = 1
Deck(FirstCard).AlreadyMatched = 1: Deck(SecondCard).AlreadyMatched = 1
hide object FirstCard: hide object SecondCard
CardsToBeMatched = 0: exitfunction
endif
FlipCardDown(FirstCard) `if nothing matches, flip first card back over and set it face down
Deck(FirstCard).FaceUp = 0
Deck(FirstCard).FaceDown = 1
FlipCardDown(SecondCard) `and flip second card back over and set it to face down
Deck(SecondCard).FaceUp = 0
Deck(SecondCard).FaceDown = 1
CardsToBeMatched = 0 `set the # of cards sent to this function back to zero for next test
endif
ENDFUNCTION
FUNCTION CardAssign() `dictates which objects are which cards
for a = 1 to 52
select a
case 1:; Deck(a).two = 1; Deck(a).Suit = 1; color object a, rgb(255,0,0); endcase `two of hearts
case 2:; Deck(a).two = 1; Deck(a).Suit = 2; color object a, rgb(255,0,0); endcase `two of spades
case 3:; Deck(a).two = 1; Deck(a).Suit = 3; color object a, rgb(255,0,0); endcase `two of clubs
case 4:; Deck(a).two = 1; Deck(a).Suit = 4; color object a, rgb(255,0,0); endcase `two of diamonds
case 5:; Deck(a).three = 1; Deck(a).Suit = 1; color object a, rgb(0,255,0); endcase `three of hearts
case 6:; Deck(a).three = 1; Deck(a).Suit = 2; color object a, rgb(0,255,0); endcase `three of spades
case 7:; Deck(a).three = 1; Deck(a).Suit = 3; color object a, rgb(0,255,0); endcase `three of clubs
case 8:; Deck(a).three = 1; Deck(a).Suit = 4; color object a, rgb(0,255,0); endcase `three of diamonds
case 9:; Deck(a).four = 1; Deck(a).Suit = 1; color object a, rgb(0,0,255); endcase `four of hearts
case 10:; Deck(a).four = 1; Deck(a).Suit = 2; color object a, rgb(0,0,255); endcase `four of spades
case 11:; Deck(a).four = 1; Deck(a).Suit = 3; color object a, rgb(0,0,255); endcase `four of clubs
case 12:; Deck(a).four = 1; Deck(a).Suit = 4; color object a, rgb(0,0,255); endcase `four of diamonds
case 13:; Deck(a).five = 1; Deck(a).Suit = 1; color object a, rgb(255,255,0); endcase `five of hearts
case 14:; Deck(a).five = 1; Deck(a).Suit = 2; color object a, rgb(255,255,0); endcase `five of spades
case 15:; Deck(a).five = 1; Deck(a).Suit = 3; color object a, rgb(255,255,0); endcase `five of clubs
case 16:; Deck(a).five = 1; Deck(a).Suit = 4; color object a, rgb(255,255,0); endcase `five of diamonds
case 17:; Deck(a).six = 1; Deck(a).Suit = 1; color object a, rgb(255,0,255); endcase `six of hearts
case 18:; Deck(a).six = 1; Deck(a).Suit = 2; color object a, rgb(255,0,255); endcase `six of spades
case 19:; Deck(a).six = 1; Deck(a).Suit = 3; color object a, rgb(255,0,255); endcase `six of clubs
case 20:; Deck(a).six = 1; Deck(a).Suit = 4; color object a, rgb(255,0,255); endcase `six of diamonds
case 21:; Deck(a).seven = 1; Deck(a).Suit = 1; color object a, rgb(0,255,255); endcase `seven of hearts
case 22:; Deck(a).seven = 1; Deck(a).Suit = 2; color object a, rgb(0,255,255); endcase `seven of spades
case 23:; Deck(a).seven = 1; Deck(a).Suit = 3; color object a, rgb(0,255,255); endcase `seven of clubs
case 24:; Deck(a).seven = 1; Deck(a).Suit = 4; color object a, rgb(0,255,255); endcase `seven of diamonds
case 25:; Deck(a).eight = 1; Deck(a).Suit = 1; color object a, rgb(255,255,255); endcase `eight of hearts
case 26:; Deck(a).eight = 1; Deck(a).Suit = 2; color object a, rgb(255,255,255); endcase `eight of spades
case 27:; Deck(a).eight = 1; Deck(a).Suit = 3; color object a, rgb(255,255,255); endcase `eight of clubs
case 28:; Deck(a).eight = 1; Deck(a).Suit = 4; color object a, rgb(255,255,255); endcase `eight of diamonds
case 29:; Deck(a).nine = 1; Deck(a).Suit = 1; color object a, rgb(0,0,0); endcase `nine of hearts
case 30:; Deck(a).nine = 1; Deck(a).Suit = 2; color object a, rgb(0,0,0); endcase `nine of spades
case 31:; Deck(a).nine = 1; Deck(a).Suit = 3; color object a, rgb(0,0,0); endcase `nine of clubs
case 32:; Deck(a).nine = 1; Deck(a).Suit = 4; color object a, rgb(0,0,0); endcase `nine of diamonds
case 33:; Deck(a).ten = 1; Deck(a).Suit = 1; color object a, rgb(125,125,125); endcase `ten of hearts
case 34:; Deck(a).ten = 1; Deck(a).Suit = 2; color object a, rgb(125,125,125); endcase `ten of spades
case 35:; Deck(a).ten = 1; Deck(a).Suit = 3; color object a, rgb(125,125,125); endcase `ten of clubs
case 36:; Deck(a).ten = 1; Deck(a).Suit = 4; color object a, rgb(125,125,125); endcase `ten of diamonds
case 37:; Deck(a).jack = 1; Deck(a).Suit = 1; color object a, rgb(0,125,125); endcase `jack of hearts
case 38:; Deck(a).jack = 1; Deck(a).Suit = 2; color object a, rgb(0,125,125); endcase `jack of spades
case 39:; Deck(a).jack = 1; Deck(a).Suit = 3; color object a, rgb(0,125,125); endcase `jack of clubs
case 40:; Deck(a).jack = 1; Deck(a).Suit = 4; color object a, rgb(0,125,125); endcase `jack of diamonds
case 41:; Deck(a).queen = 1; Deck(a).Suit = 1; color object a, rgb(125,0,125); endcase `queen of hearts
case 42:; Deck(a).queen = 1; Deck(a).Suit = 2; color object a, rgb(125,0,125); endcase `queen of spades
case 43:; Deck(a).queen = 1; Deck(a).Suit = 3; color object a, rgb(125,0,125); endcase `queen of clubs
case 44:; Deck(a).queen = 1; Deck(a).Suit = 4; color object a, rgb(125,0,125); endcase `queen of diamonds
case 45:; Deck(a).king = 1; Deck(a).Suit = 1; color object a, rgb(125,125,0); endcase `king of hearts
case 46:; Deck(a).king = 1; Deck(a).Suit = 2; color object a, rgb(125,125,0); endcase `king of spades
case 47:; Deck(a).king = 1; Deck(a).Suit = 3; color object a, rgb(125,125,0); endcase `king of clubs
case 48:; Deck(a).king = 1; Deck(a).Suit = 4; color object a, rgb(125,125,0); endcase `king of diamonds
case 49:; Deck(a).ace = 1; Deck(a).Suit = 1; color object a, rgb(147,183,44); endcase `ace of hearts
case 50:; Deck(a).ace = 1; Deck(a).Suit = 2; color object a, rgb(147,183,44); endcase `ace of spades
case 51:; Deck(a).ace = 1; Deck(a).Suit = 3; color object a, rgb(147,183,44); endcase `ace of clubs
case 52:; Deck(a).ace = 1; Deck(a).Suit = 4; color object a, rgb(147,183,44); endcase `ace of diamonds
endselect
next a
ENDFUNCTION
to see the phenomenon i'm talking about comment out the Shuffle() function right above the main loop (under the CardAssign() function) and run the program, you'll see that the matching works fine when you click on the cards and that the cards are in order (unshuffled). now run the program with the Shuffle() function uncommented and you'll see the colors randomly distributed, however you'll see that cards with matching colors don't match. and if you click the cards that are next to each other, you'll discover that the card values haven't moved from their original unshuffled positions(the red 2 cards are still the first 4 cards, then the green 3's...etc.) even though the colors are changed. I need to shuffle the actual values of the cards, and the colors(which will be the textures once i make them) to stay with their designated cards. Please help and thank you
DBPro User
PC: WinXP, AthlonXP 2100+ 1.7ghz, 80gb HD, Nvidia GeForce FX 5200 (128mb onboard RAM), 512mb DDR400 system RAM. Thank you for your help.