Hello
I am attempting at making a Dice Simulator Game using classes and objects. In theory I require two dice to "roll" upon pressing the spacebar. I have most of the code done (in my opinion) but now the window keeps closing after I press Space. Any ideas?
In the following code I turned the second die into a comment just so I can try to resolve the issue with one die first.
Thanks in advance!
// include the Dark GDK header file (http://forum.thegamecreators.com/?m=forum_read&i=22)
#include "DarkGDK.h"
class Die
{
private:
int toss;
public:
void dieToss();
//void dieTossTwo();
};
void Die::dieToss()
{
toss = dbRND(5);
if ( dbSpaceKey() )
{
toss;
if (toss == 0)
{
dbLoadImage("die1.bmp", 1);
dbPasteImage(1, 200, 120);
}
if (toss == 1)
{
dbLoadImage("die2.bmp", 1);
dbPasteImage(1, 200, 120);
}
if (toss == 2)
{
dbLoadImage("die3.bmp", 1);
dbPasteImage(1, 200, 120);
}
if (toss == 3)
{
dbLoadImage("die4.bmp", 1);
dbPasteImage(1, 200, 120);
}
if (toss == 4)
{
dbLoadImage("die5.bmp", 1);
dbPasteImage(1, 200, 120);
}
if (toss == 5)
{
dbLoadImage("die6.bmp", 1);
dbPasteImage(1, 200, 120);
}
}
}
/*
void dieTossTwo()
{
int toss = dbRND(5);
if ( dbSpaceKey() )
{
toss;
if (toss == 0)
{
dbLoadImage("die1.bmp", 1);
dbPasteImage(1, 300, 120);
}
if (toss == 1)
{
dbLoadImage("die2.bmp", 1);
dbPasteImage(1, 300, 120);
}
if (toss == 2)
{
dbLoadImage("die3.bmp", 1);
dbPasteImage(1, 300, 120);
}
if (toss == 3)
{
dbLoadImage("die4.bmp", 1);
dbPasteImage(1, 300, 120);
}
if (toss == 4)
{
dbLoadImage("die5.bmp", 1);
dbPasteImage(1, 300, 120);
}
if (toss == 5)
{
dbLoadImage("die6.bmp", 1);
dbPasteImage(1, 300, 120);
}
}
}
*/
// main entry point for the application
void DarkGDK ()
{
Die myDie;
myDie.dieToss();
dbPrint("Press Space to roll the dice");
dbSyncRate(60);
dbSync();
// Pause the program until the user presses a key.
dbWaitKey();
}
-HAVE A NICE DAY!