|
#include <iostream>
#include <string.h>
#include <time.h>
using namespace std;
#define max_n 50
#define blank '_'
char input[max_n];
char answer[max_n];
int err_count = 0;
char dictionary[][max_n] = {"Rose", "Audio", "Bible", "Earth", "Movie", "Space", "Good", "Enterprise", "University", "Tomorrow",
"Professor", "Parent", "Korea", "Basketball", "Computer", "Programming", "C++_rule_the_world!!", "Amazing", "Apple", "Marathon"};
void display(int stage)
{
switch (stage)
{
case 99:
cout << "----------- GAME START -----------\n";
break;
case 0:
cout << " \n";
break;
case 1:
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " \n";
cout << " -+---- \n";
break;
case 2:
cout << " \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 3:
cout << " +--- \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 4:
cout << " +--- \n";
cout << " | | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 5:
cout << " +--- \n";
cout << " | | \n";
cout << " | o \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 6:
cout << " +--- \n";
cout << " | | \n";
cout << " | o \n";
cout << " | | \n";
cout << " | | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 7:
cout << " +--- \n";
cout << " | | \n";
cout << " | o \n";
cout << " | -| \n";
cout << " | | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 8:
cout << " +--- \n";
cout << " | | \n";
cout << " | o \n";
cout << " | -|- \n";
cout << " | | \n";
cout << " | \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 9:
cout << " +--- \n";
cout << " | | \n";
cout << " | o \n";
cout << " | -|- \n";
cout << " | | \n";
cout << " | / \n";
cout << " | \n";
cout << " -+---- \n";
break;
case 10:
cout << " +--- \n";
cout << " | | \n";
cout << " | o \n";
cout << " | -|- \n";
cout << " | | \n";
cout << " | // \n";
cout << " | \n";
cout << " -+---- \n";
break;
}
cout << "ANSWER: ";
for (int i = 0; i < strlen(answer); ++i) cout << input[i];
cout << endl;
}
void init()
{
err_count = 0;
srand(time(NULL));
sprintf(answer, "%s\0", dictionary[rand()%20]);
memset(input, blank, max_n * sizeof(char));
display(99);
}
int main()
{
init();
while (true)
{
cout << "Input alpa: ";
char c;
cin >> c;
c = tolower(c);
int match_count = 0;
for (int i = 0; i < strlen(answer); ++i)
{
if (input[i] == blank && tolower(answer[i]) == tolower(c))
{
input[i] = answer[i];
++match_count;
}
}
if (match_count == 0) ++err_count;
else cout << match_count << (match_count == 1 ? "match!" : "matches!!") << endl;
display(err_count);
if (!strncmp(input, answer, strlen(answer)))
{
cout << "Success!!" << endl;
cout << "More Game?(y/n): " << endl;
char c;
cin >> c;
if (tolower(c) == 'n') exit(0);
init();
}
if (err_count == 10)
{
cout << "Failed!!" << endl;
cout << "Continue?(y/n): ";
char c;
cin >> c;
if (tolower(c) == 'n') exit(0);
init();
}
}
}
|