simon says

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!

this is the code:

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <string.h>
using namespace std;

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);


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");
}
Please use [code][/code] tags when posting code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <cstdio>   // #include <stdio.h>
#include <iostream>
#include <cstdlib>  // #include <stdlib.h>
#include <ctime>    // #include <time.h>
//#include <windows.h>
#include <string>
using namespace 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.

4. Break the problem down into smaller steps.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

struct player {
  string name;
  int points;
  char difficulty;
};

void playBeginner(player &p) {
  bool gameOver = false;
  string sec_user;
  string sequence = "";
  while ( !gameOver ) {
    // at some point, decide
    gameOver = true;
  }
}

void playIntermediate(player &p) {
}

void playAdvanced(player &p) {
}


int main()
{
  srand(time(NULL));
  player 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;
  }
  cout << ".::select level::.\n\n(b)Beginner\n\n(i)Intermediate\n\n(a)Advanced\n";
  cin >> j1.difficulty;

  if (j1.difficulty == 'b') {
    playBeginner(j1);
  }
  else if (j1.difficulty == 'i') {
    playIntermediate(j1);
  }
  else if (j1.difficulty == 'a') {
    playAdvanced(j1);
  }
}

Work on playBeginner first, without regard to difficulty.

Difficulty can be added later, when the basic code works.
Thanks!
It's not "simon says"; it's just "simon". https://en.wikipedia.org/wiki/Simon_(game)
"Simon says" would be a very strange computer game indeed! https://en.wikipedia.org/wiki/Simon_Says
Last edited on
Topic archived. No new replies allowed.