I am making a game program in turbo c++ for my project and I need help on how to add a game timer, I've seen videos on how to create timer using while loop but I don't know how to implement it to my game. My plan for my game is to have it show 6 initialized letters(ex. "N A E B T S") and within 30 secs input as many words as possible which has corresponding points(6=10pts, 5=8pts, 4=6pts, 3=4pts). The correct words are written in a txt file with their corresponding points. Also the whole thing is in loop with clrscr();
Here is some parts of the game code:
void start()
{
char arr[10][50] = {" B A N S E T ",
" L E A Z D Z ",
" M B L U E J ",
" P R G N I S ",
" A C Q U K Y ",
" S A H L E S ",
" R E D G A E ",
" Z E D Z U B "};
int i = 0;
int sum = 0;
int x = 0;
do
{
clrscr();
cout << "
SCORE: " << sum << " pts"
<< "
******************************
";
cout << " * " << arr[i] << " *
";
cout << " ******************************
";
char a[50], b[50];
int c;
if (arr[0])
{
ifstream fin;
fin.open("lvl1.txt");
if (fin.fail())
{
cout << "File doesn't exist!";
exit(1);
}
cout << "Enter word: ";
cin >> a;
do
{
fin >> b >> c;
if (fin.eof() == 1)
{
cout << "Incorrect! Try Again!";
delay(1500);
exit(1);
}
} while (strcmp(a, b) != 0);
fin.close();
if (strcmp(a, b) == 0)
{
sum += c;
}
}
} while(s != 0);
}
See Question&Answers more detail:os