Computer Science Canada memory card game help |
Author: | noname96 [ Sun Jan 20, 2013 1:03 pm ] |
Post subject: | memory card game help |
hi, i'm new to the forums:) i'm making a concentration matching card game.The game will show 16 cards(4 by 4), and 8 different pictures. the user will click on two cards,and if they match they stay flipped over. if they don't, they return to their face down position. how do i make the pictures appear in different positions each time i run the program? also, how do i make it so you can only flip two cards at a time? Ive added 5 of the pictures as attachments, however it wont allow me to add all 8. the ones i didnt include were PEAR.jpg, APPLE.jpg, and BANANA.jpg. Help MUCH appreciated. Thank you setscreen ("graphics:1201;601;cursor;nobuttonbar") View.Set ("offscreenonly") var picID : int Draw.FillBox (0, 1, 1203, 600, 7) var temp : int := Rand.Int (1, 16) var stream : int var word : string var select : array 1 .. 4, 1 .. 4 of boolean var pic : array 1 .. 16 of int var X : int var Y : int var X2 : int var Y2 : int for r : 1 .. 4 for c : 1 .. 4 select (r, c) := true end for end for %%%%%%%%%%%%%%%%%%%%%%%%%%%%%randomizing picture array%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pic (1) := Pic.FileNew ("ORANGE.jpg") pic (2) := Pic.FileNew ("WATERMELON.jpg") pic (3) := Pic.FileNew ("STRAWBERRIES.jpg") pic (4) := Pic.FileNew ("PUMPKIN.jpg") pic (5) := Pic.FileNew ("BANANA.jpg") pic (6) := Pic.FileNew ("APPLE.jpg") pic (7) := Pic.FileNew ("PEAR.jpg") pic (8) := Pic.FileNew ("MANGO.jpg") pic (9) := Pic.FileNew ("ORANGE.jpg") pic (10) := Pic.FileNew ("WATERMELON.jpg") pic (11) := Pic.FileNew ("STRAWBERRIES.jpg") pic (12) := Pic.FileNew ("PUMPKIN.jpg") pic (13) := Pic.FileNew ("BANANA.jpg") pic (14) := Pic.FileNew ("APPLE.jpg") pic (15) := Pic.FileNew ("PEAR.jpg") pic (16) := Pic.FileNew ("MANGO.jpg") for i : 1 .. 16 end for %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FACE DOWN CARD%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var counter : int := 0 var x, y, button : int var click : boolean := true procedure fill var x2, x3, y2, y3 : int y2 := 543 y3 := 420 for i : 1 .. 4 x2 := 30 x3 := 150 for j : 1 .. 4 if select (i, j) = true then Draw.FillBox (x2, y2, x3, y3, red) end if if select (i, j) = false then Draw.FillBox (x2, y2, x3, y3, white) Pic.Draw (pic (temp), x2 + 1, y3 + 1, picCopy) Draw.Box (x2, y2, x3, y3, 3) end if x2 += 130 x3 += 130 end for y2 -= 130 y3 -= 130 end for end fill procedure find var x2, y2 : int := 0 Mouse.Where (x, y, button) for r : 1 .. 4 x2 := 0 for c : 1 .. 4 if x > 30 + x2 and x < 150 + x2 and y < 542 + y2 and y > 420 + y2 and button not= 0 then select (r, c) := false end if x2 += 130 end for y2 -= 130 end for end find %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%mouse locate help%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% loop Mouse.Where (x, y, button) Text.Locate (1, 1) if button = 0 then put x : 4, " ", y : 4, " button up" else put x : 4, " ", y : 4, " button down" end if find fill View.Update end loop |
Author: | noname96 [ Sun Jan 20, 2013 6:44 pm ] |
Post subject: | Re: memory card game help |
Oh, and to add, right now i get one random picture throughout all the cards when i run it each time. However, what i want is a DIFFERENT picture in each card randomly arranged. EDIT: i guess ill add the remaining pictures here. |
Author: | Tony [ Sun Jan 20, 2013 7:48 pm ] |
Post subject: | Re: memory card game help |
noname96 @ Sun Jan 20, 2013 1:03 pm wrote: var temp : int := Rand.Int (1, 16) you seem to already know how to get random numbers. |
Author: | noname96 [ Sun Jan 20, 2013 9:08 pm ] |
Post subject: | Re: memory card game help |
Yes, but i dont know how to translate these random numbers into pictures. i put: temp:=Rand.Int(1,16) %%%and then in my fill procedure%%%% Pic.FileNew(pic(temp) x2,y3,PicCopy) but all this does is put 1 random picture in all 16 cards. i want a random picture in each card. |
Author: | DemonWasp [ Sun Jan 20, 2013 9:15 pm ] | ||||
Post subject: | Re: memory card game help | ||||
noname96 @ Sun Jan 20, 2013 9:08 pm wrote: temp:=Rand.Int(1,16)
That will make temp hold a particular, single, random value. If you want different random values, you'll have to write code that uses Rand.Int repeatedly. For example, this produces the same value 5 times:
Whereas this produces 5 separately-random values (possibly the same, probably different):
|
Author: | noname96 [ Sun Jan 20, 2013 9:25 pm ] |
Post subject: | Re: memory card game help |
thanks, that last one makes sense! ![]() Pic.Draw(pic(temp)x2,y3,PicCopy) but what? i would also need to make sure that the picture doesnt repeat itself, but one step at a time i guess ![]() |
Author: | Tony [ Mon Jan 21, 2013 1:15 am ] |
Post subject: | RE:memory card game help |
Lets say that you've already decided which picture is what (using Rand.Int). For example, you have: slot #1: picture 3 slot #2: picture 5 slot #3: picture 1 ... etc. What kind of a data structure can you use to easily look up what kind of picture you would need to draw in a specific slot? The answer to that should lead towards the design of all the other parts (such as picking out the values). |
Author: | noname96 [ Mon Jan 21, 2013 12:29 pm ] |
Post subject: | Re: memory card game help |
Alright, I got it to work thanks! But now I'm struggling to make it so that I can Only click two at a time. I tried putting a counter, and makin it add one evrytime you click, but that doesn't work for some reason... |
Author: | Tony [ Mon Jan 21, 2013 1:04 pm ] |
Post subject: | RE:memory card game help |
okay... in which way dose it not work? |
Author: | noname96 [ Mon Jan 21, 2013 5:13 pm ] |
Post subject: | Re: memory card game help |
the problem is that when i run it, the cards don't flip over. not even two. this is how i coded it: select(i,j):=false clicktwo:=clicktwo+1 if clicktwo=2 then select(i,j):=true if you read my code that i put in my original post youll see what select(i,j) does. basically if it is true, then the cards will be covered by a fillbox. if is false then the picture will show. |