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 issue

Author
Message
Crook County
11
Years of Service
User Offline
Joined: 9th Aug 2013
Location:
Posted: 9th Aug 2013 12:08 Edited at: 9th Aug 2013 19:01
I am creating a memory game for my class and I am having a problem with the mouse click. Once I have clicked it it seems to be constantly performing every statement within the if mouseclick check. As a test I put a break in it and it shouldn't be performing this loop break yet.



#include "DarkGDK.h"
#include <algorithm>

using namespace std;

void loadImages();
void drawCardBacks(int [], int);

// main entry point for the application
void DarkGDK()
{
const int SIZE = 12;
int values[SIZE]={1,2,3,4,5,6,7,8,9,10, 11, 12};
int number = 1, data, player = 1, move = 1;


dbCLS();

dbSetWindowTitle("Memory Match");

dbRandomize ( dbTimer () );

loadImages();

dbSyncOn();
dbSyncRate(60);



random_shuffle(&values[0], &values[11]);

drawCardBacks(values, SIZE);



while (LoopGDK())
{


dbText(0,464,"Player:");
dbText(64,464,dbStr(player));
dbText(128,464,"Move:");
dbText(176,464,dbStr(move));

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 0 && dbMouseX() <= 128 && dbMouseY() >= 0 && dbMouseY() <= 128)
{
if ( move == 3 )
{
break;
}
if ( move == 2 )
{
dbPasteImage(values[0],0,0,1);
move = 3;
}
if ( move == 1)
{
dbPasteImage(values[0],0,0,1);
move = 2;
}
}


if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 160 && dbMouseX() <= 288 && dbMouseY() >= 0 && dbMouseY() <= 128)
{
dbPasteImage(values[1],160,0,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 320 && dbMouseX() <= 448 && dbMouseY() >= 0 && dbMouseY() <= 128)
{
dbPasteImage(values[2],320,0,1);
}

if (dbMouseClick() == 1 )
if ( dbMouseX() >= 480 && dbMouseX() <= 608 && dbMouseY() >= 0 && dbMouseY() <= 128)
{
dbPasteImage(values[3],480,0,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 0 && dbMouseX() <= 128 && dbMouseY() >= 160 && dbMouseY() <= 228)
{
dbPasteImage(values[4],0,160,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 160 && dbMouseX() <= 288 && dbMouseY() >= 160 && dbMouseY() <= 228)
{
dbPasteImage(values[5],160,160,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 320 && dbMouseX() <= 448 && dbMouseY() >= 160 && dbMouseY() <= 228)
{
dbPasteImage(values[6],320,160,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 480 && dbMouseX() <= 608 && dbMouseY() >= 160 && dbMouseY() <= 228)
{
dbPasteImage(values[7],480,160,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 0 && dbMouseX() <= 128 && dbMouseY() >= 320 && dbMouseY() <= 448)
{
dbPasteImage(values[8],0,320,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 160 && dbMouseX() <= 288 && dbMouseY() >= 320 && dbMouseY() <= 448)
{
dbPasteImage(values[9],160,320,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 320 && dbMouseX() <= 448 && dbMouseY() >= 320 && dbMouseY() <= 448)
{
dbPasteImage(values[10],320,320,1);
}

if ( dbMouseClick() == 1 )
if ( dbMouseX() >= 480 && dbMouseX() <= 608 && dbMouseY() >= 320 && dbMouseY() <= 448)
{
dbPasteImage(values[11],480,320,1);
}

dbSync();

}

}

void loadImages()
{
dbLoadImage("C:\\Images\\Apple.bmp", 1);
dbLoadImage("C:\\Images\\Banana.bmp", 2);
dbLoadImage("C:\\Images\\Grape.bmp", 3);
dbLoadImage("C:\\Images\\Orange.bmp", 4);
dbLoadImage("C:\\Images\\Strawberry.bmp", 5);
dbLoadImage("C:\\Images\\Watermelon.bmp", 6);
dbLoadImage("C:\\Images\\Apple.bmp", 7);
dbLoadImage("C:\\Images\\Banana.bmp", 8);
dbLoadImage("C:\\Images\\Grape.bmp", 9);
dbLoadImage("C:\\Images\\Orange.bmp", 10);
dbLoadImage("C:\\Images\\Strawberry.bmp", 11);
dbLoadImage("C:\\Images\\Watermelon.bmp", 12);
dbLoadImage("C:\\Images\\Card_Back.bmp", 13);
dbLoadImage("C:\\Images\\Null.png",0);
}

void drawCardBacks(int amount[], int size)
{
int x = 0, y = 0, image = 0;

for (int i = 0; i < size; i ++)
{
image = amount[i];
dbPasteImage(13, x, y, 1);
x = x + 160;
if (x == 640)
{
y += 160;
x = 0;
}
}
}


Never mind I finally figured it out I just needed to slow the sync rate down.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 9th Aug 2013 20:52
Glad you figured it out.
[ code ]<insert code snippet here>[ /code ] tags are your friend by the way; among other things they allow your pasted code to retain intendation


"Why do programmers get Halloween and Christmas mixed up?"
Crook County
11
Years of Service
User Offline
Joined: 9th Aug 2013
Location:
Posted: 11th Aug 2013 20:00
Thanks, still learning the forum
TimmyTopHat
11
Years of Service
User Offline
Joined: 29th Aug 2013
Location:
Posted: 29th Aug 2013 03:29
Why use so many IF statements? Why not a switch?

Indie Programmer - DirectX 11

Login to post a reply

Server time is: 2024-11-18 21:49:16
Your offset time is: 2024-11-18 21:49:16