Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / memory game problem

Author
Message
lilly new beginner
13
Years of Service
User Offline
Joined: 3rd Jun 2011
Location:
Posted: 3rd Jun 2011 15:38
hi all, I'm a new beginner for using Dark GDK..
and I'm doing a memory game..
I drew all the cards and when I click on one of them it rotates..
but I don't know how to compare two pictures with each other and how to relate the picture underneath the card to the card itself..

here's the code I did so far..

#include "DarkGDK.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void LoadImage();
void Rotate();
const int REFRESH_RATE = 60;
const int s = 14;
const int stat=15;
const int statue=16;
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
const int SIZE = 4;// Refresh rate
dbRandomize ( dbTimer ( ) );
LoadImage();
while ( LoopGDK ( ) )
{
Rotate();
dbSync ( );
}
return;
}
//----------------------------------------------------------
void LoadImage()
{
dbLoadImage("stat.jpg",stat);
dbSprite(stat,60,50,stat);
dbLoadImage("statue.jpg",statue);
dbSprite(statue,190,160,statue);

dbLoadImage("square.bmp", s);
dbSprite(1,30,20,s);
dbSprite(2,150,20,s);
dbSprite(3,270,20,s);
dbSprite(4,390,20,s);
dbSprite(5,30,120,s);
dbSprite(6,150,120,s);
dbSprite(7,270,120,s);
dbSprite(8,390,120,s);
dbSprite(9,30,220,s);
dbSprite(10,150,220,s);
dbSprite(11,270,220,s);
dbSprite(12,390,220,s);


}
//-----------------------------------------------------------
void Rotate()
{
dbLoadImage("pointer.png",150);
dbSprite(150,dbMouseX(),dbMouseY(),150);
dbHideSprite(150);

if (dbSpriteCollision(150,1)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(1,dbSpriteWidth(2)/2,dbSpriteHeight(2)/2);
}
else if (dbSpriteCollision(150,2)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(2,dbSpriteWidth(2)/2,dbSpriteHeight(2)/2);
}
else if (dbSpriteCollision(150,3)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(3,dbSpriteWidth(3)/2,dbSpriteHeight(3)/2);
}
else if (dbSpriteCollision(150,4)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(4,dbSpriteWidth(4)/2,dbSpriteHeight(4)/2);
}
else if (dbSpriteCollision(150,5)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(5,dbSpriteWidth(5)/2,dbSpriteHeight(5)/2);
}
else if (dbSpriteCollision(150,6)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(6,dbSpriteWidth(6)/2,dbSpriteHeight(6)/2);
}
else if (dbSpriteCollision(150,7)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(7,dbSpriteWidth(7)/2,dbSpriteHeight(7)/2);
}
else if (dbSpriteCollision(150,8)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(8,dbSpriteWidth(8)/2,dbSpriteHeight(8)/2);
}
else if (dbSpriteCollision(150,9)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(9,dbSpriteWidth(9)/2,dbSpriteHeight(9)/2);
}
else if (dbSpriteCollision(150,10)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(10,dbSpriteWidth(10)/2,dbSpriteHeight(10)/2);
}
else if (dbSpriteCollision(150,11)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(11,dbSpriteWidth(11)/2,dbSpriteHeight(11)/2);
}
else if (dbSpriteCollision(150,12)==1 && dbMouseClick()==1)
{
dbWait(250);
dbOffsetSprite(12,dbSpriteWidth(12)/2,dbSpriteHeight(12)/2);
}

}


please reply me as fast as you can...thank you
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 9th Jun 2011 21:25
Ok, one problem I see here is that you have [/code]void Rotate()
{
dbLoadImage("pointer.png",150);[code]

That load image should really be before the main loop. Anywhere just before the main loop would be fine.

*sigh* I would have made this a completely different way... or, wait, I made this a completely different way. Unfortunately, That was on a TI 84...*sigh*

I would suggest this approach. Q: How many cards do you want? A: X
Make an array "cards[X][2]". In each member of the array that has address [n][0] store the sprite number of the card. In each member that has address [n][1] store the image number for the face of that type of card.

In every refresh, loop through (use a loop to check every member of) the array to see if there is a collision between the mouse sprite and the card sprites.
If there is a collision and the mouse is being clicked after having not been clicked the refresh before, then the card may be flipped.

To flip a card, simply replace the image of sprite card[n][0] with card[n][1] if the collision occurred with card[n][0].

You will also need to keep track of how many and which cards are flipped.

To check for a match when sprites open1 and open2 are flipped, simply verify that card[open1][1]==card[open2][1] and you have a match!

I hope this helps!

PS
This explanation is pretty vague so let me know where you need clarification.


Login to post a reply

Server time is: 2024-11-19 10:39:42
Your offset time is: 2024-11-19 10:39:42