This should display 100 different words (only two distinct word right now), and for each word, wait for the user to press the up or down arrow key. If they press up, say "You Won.", if they press down, say "You Fail.", and either way increase a variable which indicates which word to print. Oh, and, if within 5 seconds, no key is pressed, then go on to the next word. It works nothing like it should. Please help me! Oh, and it is written in DarkGDK on Visual C++ 2008 Express.
#include "DarkGDK.h"
#define NO_KEY 0
#define DOWN_KEY 1
#define UP_KEY 2
int iTextIndex = 0;
int iMilliTime = 0;
bool failed = false;
bool won = false;
int getPressedKey();
bool running();
void noKeyPressed();
void upKeyPressed();
void downKeyPressed();
void partOne();
void partTwo();
void DarkGDK()
{
while (iTextIndex <= 100)
{
while (running())
{
if (dbEscapeKey())
return;
partOne();
}
}
}
int getPressedKey()
{
if (dbUpKey())
return UP_KEY;
if (dbDownKey())
return DOWN_KEY;
else return NO_KEY;
}
void noKeyPressed()
{
iMilliTime ++;
dbSleep(1);
switch(iTextIndex)
{
case 0:
dbText(64, 64, "House");
dbSync();
case 1:
dbText(64, 64, "Cat");
dbSync();
default:
dbText(64, 64, ".");
dbSync();
}
return;
}
void success()
{
iTextIndex ++;
dbCLS();
dbText(64, 64, "You Won.");
dbSync();
dbWait(5000);
dbCLS();
iMilliTime = 0;
return;
}
void failure()
{
iTextIndex ++;
dbText(64, 64, "You Fail.");
dbSync();
dbWait(5000);
dbCLS();
iMilliTime = 0;
return;
}
void partOne()
{
switch(getPressedKey())
{
case NO_KEY:
noKeyPressed();
case UP_KEY:
success();
case DOWN_KEY:
failure();
}
}
bool running()
{
if (iMilliTime <= 3000)
return true;
else
return false;
}