Hello! I need help for a program that I am developing, it is the famous game "simon says".
my problem is that I do not know how to continue to play, i mean, the game generates a letter (which is assigned to a color) but if the user hits I do not know how to make the game continue.
It would be fantastic if someone could help me do it, thank you!
struct player{
string name;
int points;
char difficulty;
};
main(){
int num;
srand(time(NULL));
string sec_user;
string sequence="";
int round=1;
jugador j1;
cout <<".::welcome to SIMON ver. 1.0.::." <<endl;
cout <<" your name (fin=end of the game):" <<endl;
cin >>j1.name;
if(j1.name=="fin")
{return 0;}
system("cls");
cout <<".::select level::.\n\n(b)Beginner\n\n(i)Intermediate\n\n(a)Advanced\n";
cin >>j1.difficulty;
system("pause");
system("cls");
Sleep(500);
#include <cstdio> // #include <stdio.h>
#include <iostream>
#include <cstdlib> // #include <stdlib.h>
#include <ctime> // #include <time.h>
//#include <windows.h>
#include <string>
usingnamespace std;
struct player {
string name;
int points;
char difficulty;
};
int main() //!! yes, really! main returns int
{
int num;
srand(time(NULL));
string sec_user;
string sequence = "";
int round = 1;
jugador j1; //!! this is player right?
cout << ".::welcome to SIMON ver. 1.0.::." << endl;
cout << " your name (fin=end of the game):" << endl;
cin >> j1.name;
if (j1.name == "fin") {
return 0;
}
//system("cls");
cout << ".::select level::.\n\n(b)Beginner\n\n(i)Intermediate\n\n(a)Advanced\n";
cin >> j1.difficulty;
//system("pause");
//system("cls");
//Sleep(500);
num = rand() % 4;
switch (num) {
case 0:
cout << "A";
//system("color 1F");
//Beep(700, 400);
if (j1.difficulty == 'b') {
//Sleep(1000);
}
if (j1.difficulty == 'i') {
//Sleep(500);
}
if (j1.difficulty == 'a') {
//Sleep(100);
};
//system("cls");
break;
case 1:
cout << "N";
//system("color 6F");
//Beep(400, 500);
if (j1.difficulty == 'b') {
//Sleep(1000);
}
if (j1.difficulty == 'i') {
//Sleep(500);
}
if (j1.difficulty == 'a') {
//Sleep(100);
}
//system("cls");
break;
case 2:
cout << "V";
//system("color 2F");
//Beep(900, 500);
if (j1.difficulty == 'b') {
//Sleep(1000);
}
if (j1.difficulty == 'i') {
//Sleep(500);
}
if (j1.difficulty == 'a') {
//Sleep(100);
}
//system("cls");
break;
case 3:
cout << "R";
//system("color CF");
//Beep(200, 500);
if (j1.difficulty == 'b') {
//Sleep(1000);
}
if (j1.difficulty == 'i') {
//Sleep(500);
}
if (j1.difficulty == 'a') {
//Sleep(100);
}
//system("cls");
break;
}
if (num == 0) {
sequence = sequence + 'a';
}
if (num == 1) {
sequence = sequence + 'n';
}
if (num == 2) {
sequence = sequence + 'v';
}
if (num == 3) {
sequence = sequence + 'r';
}
//system("color 0F");
cout << "enter the sequence: " << endl;
cin >> sec_user;
if (sec_user == sequence)
cout << "correct" << endl;
else
cout << "error" << endl;
//system("pause");
}
General comments.
1. Your C++ compiler should now be accepting the new form for including 'C' standard header files like stdio.h
2. Leave all the eye/ear candy (like colours and beeps) until the end. They're dead easy to add to an otherwise working program. Before that, they just get in the way.
3. Seriously consider not having Beep at all. Programs, if they beep at all, only use it for errors.