I have selected to do a hangman console game in my C++ course (9th week) in which I have a question about wait().
I want to make the game "appear" to be loading just to give it aesthetics but I'm not sure how to do it the way I want to do it. Initially, I had it display, "LOADING GAME....", then my next line was "wait (5)" to make it appear it was loading for 5 seconds.
Now, what I want to do is have the periods after "LOADING GAME" to delay 1 second before consecutively appearing. Here is what I want to do but obviously, the syntax is incorrect but it's the concept I want to convey.
The code is incomplete as I am compiling and running incrementally to ensure each coded parts run w/o error.
The particular part, in question, is within the single IF statement:
#include<iostream>
#include<string>
#include<conio.h>
#include <ctime>
using namespace std;
void wait (int seconds)
{
clock_t endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < endwait) {}
}
int main()
{
int seconds; //
char guess; //user input
const char BLANKS = "-"; //used as a placeholder for letters not yet guessed
string
char answer[7]; //holds the answer
char hidden[7]; //holds dashes ("-") for hidden letters
int right = 0; //0 = wrong guess & 1 = right guess
int count = 0;
int countdown = 5;
string MSG_YES = "Good Job! You got it!.";
string MSG_HUNG = "Sorry, but you were hung.";
string ANSWER = "kitchen";
cout <<"\t**************************" <<endl;
cout << " " <<endl;
cout <<"\t\tHANGMAN!" <<endl;
cout << " " <<endl;
cout <<"\t\t\t**************************" <<endl;
cout <<"\n\nDIRECTIONS:" <<endl;
cout <<"\n\n1. Try to guess the computer's mystery word. " <<endl;;
cout <<"\n2. Guess your letter one at a time." <<endl;
cout <<"\n\n\n Game will begin in 5 seconds" <<endl;
cout <<"\n\n Press ENTER to begin the countdown:\n" <<endl;
getche();
for (countdown; countdown > 0; --countdown)
{
cout << countdown << " seconds \n"; //countdown decrement to be displayed on console.
wait (1); //1 second between decrements
}
if (countdown == 0) //determines when to display LOADING GAME...
{
cout << "\n\t\t\t\tLOADING GAME."wait(1)"."wait(1)"."wait(1)"."wait(1)"\n\n";
//wait(5); //waiting 5 seconds to give "appearance" of game loading
}
cin.get();
return 0;
}