Simon Colors Game advice

Right now it's just system("CLS"); and keyboard button pressing. Does anyone know how to make like a little circle with 4 lights and the ability to click?

main.cpp

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
130
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <conio.h>

#include "concor.h"
using namespace std;

void genColors(int colors[256],int round)
{
    for(int s = 0;s < round;s++)
    {
        switch(colors[s])
        {
            case 1:
                setcolor(red,red);
                break;
            case 2:
                setcolor(blue,blue);
                break;
            case 3:
                setcolor(green,green);
                break;
            case 4:
                setcolor(yellow,yellow);
                break;
            default:
                break;
        }
        system("CLS");

        Sleep(300);
        setcolor(7,black);
        system("CLS");
        Sleep(300);
    }
    setcolor(7,black);
}
int main(int nNumberofArgs,char* pszArgs[])
{
    Restart:
    int round = 1;
    int colors[256];
    char input;
    int input2;
    char input3;
    cout << "Welcome to the Simon color game!" << endl;
    system("PAUSE");
    system("CLS");

    for(;;round++)
    {
        Select:
        srand((unsigned)time(0));
        cout << "Welcome to round " << round << "!" << endl;
        cout << "R = Red, B = Blue, G = Green, Y = Yellow." << endl;
        system("PAUSE");

        for(int c = 0;c < round;c++)
        {
            colors[c] = 1 + rand() % (4);
        }
        genColors(colors,round);

        for(int c2 = 0;c2 < round;c2++)
        {
            input = getch();
            if(input == '/')
            {
                cout << "Level select: ";
                cin >> round;
                system("CLS");
                goto Select;
            }
            switch(input)
            {
                case 'r':
                case 'R':
                    input2 = 1;
                    setcolor(red,red);
                    cout << "                                                                            " << endl;
                    break;
                case 'b':
                case 'B':
                    input2 = 2;
                    setcolor(blue,blue);
                   cout << "                                                                            " << endl;
                    break;
                case 'g':
                case 'G':
                    input2 = 3;
                    setcolor(green,green);
                    cout << "                                                                            " << endl;
                    break;
                case 'y':
                case 'Y':
                    input2 = 4;
                    setcolor(yellow,yellow);
                    cout << "                                                                            " << endl;
                    break;
                default:
                    cout << "Please enter R,B,G, or Y." << endl;
            }

            setcolor(7,black);
            if(input2 != colors[c2])
            {
                cout << "You have gotten the sequence incorrect!" << endl;
                cout << "Thank you for playing!" << endl;
                cout << "Would you like to try again?(Y/N): ";
                cin >> input3;
                if(input3 == 'y' || input3 == 'Y')
                {
                    input3 = 'n';
                    system("CLS");
                    goto Restart;
                }

                system("PAUSE");
                return 0;
            }
        }
        cout << "You have won round " << round << "!" << endl;
        cout << "Now for round " << round + 1 << "!" << endl;
        system("PAUSE");
        system("CLS");
    }
}


concor.h

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
#ifndef _EKU_CONCOL
#define _EKU_CONCOL

#ifndef _INC_WINDOWS
#include <windows.h>
#endif /*_INC_WINDOWS*/

bool textcolorprotect=true;
/*doesn't let textcolor be the same as backgroung color if true*/

enum concol
{
	black=0,
	dark_blue=1,
	dark_green=2,
	dark_aqua,dark_cyan=3,
	dark_red=4,
	dark_purple=5,dark_pink=5,dark_magenta=5,
	dark_yellow=6,
	dark_white=7,
	gray=8,
	blue=9,
	green=10,
	aqua=11,cyan=11,
	red=12,
	purple=13,pink=13,magenta=13,
	yellow=14,
	white=15
};

inline void setcolor(concol textcolor,concol backcolor);
inline void setcolor(int textcolor,int backcolor);
int textcolor();/*returns current text color*/
int backcolor();/*returns current background color*/

#define std_con_out GetStdHandle(STD_OUTPUT_HANDLE)

//-----------------------------------------------------------------------------

int textcolor()
{
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	GetConsoleScreenBufferInfo(std_con_out,&csbi);
	int a=csbi.wAttributes;
	return a%16;
}

int backcolor()
{
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	GetConsoleScreenBufferInfo(std_con_out,&csbi);
	int a=csbi.wAttributes;
	return (a/16)%16;
}

inline void setcolor(concol textcol,concol backcol)
{setcolor(int(textcol),int(backcol));}

inline void setcolor(int textcol,int backcol)
{
	if(textcolorprotect)
	{if((textcol%16)==(backcol%16))textcol++;}
	textcol%=16;backcol%=16;
	unsigned short wAttributes= ((unsigned)backcol<<4)|(unsigned)textcol;
	SetConsoleTextAttribute(std_con_out, wAttributes);
}

#if defined(_INC_OSTREAM)||defined(_IOSTREAM_)
ostream& operator<<(ostream& os,concol c)
{os.flush();setcolor(c,backcolor());return os;}
#endif

#if defined(_INC_ISTREAM)||defined(_IOSTREAM_)
istream& operator>>(istream& is,concol c)
{cout.flush();setcolor(c,backcolor());return is;}
#endif

#endif /*_EKU_CONCOL*/
@greenleaf800073

This isn't exactly what you were looking for, as it isn't a window program, with mouse clicks. And, the board is not round, but square. You enter the color sequences, with the letters, 'R', 'B', 'G', and 'Y'. I'm still working on it, but you can now add your programming to it. Would love to see it after you work on it awhile.

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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Simon.cpp : main project file.

// Compiled as CLR Console Application 

#include <string>
#include <iostream>
#include <ctime>
#include <conio.h>
#include <windows.h>

enum Colors{
	black,          //  0 text color - multiply by 16, for background colors
	dark_blue,      //  1
	dark_green,     //  2
	dark_cyan,      //  3
	dark_red,       //  4
	dark_magenta,   //  5
	dark_yellow,    //  6
	light_gray,     //  7
	dark_gray,      //  8
	light_blue,     //  9
	light_green,    // 10
	light_cyan,     // 11
	light_red,      // 12
	light_magenta,  // 13
	light_yellow,   // 14
	white           // 15
};

using namespace std;


HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

#define on , // So I can use the function - void text(text_color on background_color)
// To more easily remember which is text color vs background color
void genColors(int Simon_Board[256],int round);
void Box(int, int, int, int, int, int, int, int, int, int);
void gotoXY(int,int);

// My text color function. Use it if you wish.
void setcolor(int text_color = 7 on int paper_color = 0)
{
	// defaults to light_gray on black
	int color_total = (text_color+(paper_color*16));
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color_total );
}


int main()
{
	int round = 0;
	int Simon_Board[256];
	char input;
	int input2;
	char input3;
	bool ok = false;
	int Simon_Color[4] = {4,3,2,6};
	Box(1,10,5,14,14,black on light_gray,2,black on dark_gray);
	for (int i=1;i<3;i++)
	{
		Box(2,5+(i*6),6,6,6,black on Simon_Color[i-1],0,0,0);
		Box(2,5+(i*6),12,6,6,black on Simon_Color[i+1],0,0,0);
	}
	srand((unsigned) time(0));
	setcolor();
	for(int c = 0;c < 256; c++)
		Simon_Board[c] = Simon_Color[rand()%4];

	gotoXY(18,2);
	cout << "Welcome to the Simon color game!";

	do
	{
		gotoXY(30,8);
		cout << "R = Red, B = Blue, G = Green, Y = Yellow.";
		do
		{
			gotoXY(30,7);
			cout << "Welcome to round " << round << "!";
			genColors(Simon_Board,round);
			ok = true;
			for(int ck = 0;ck < round;ck++)
			{
				input = toupper(_getch());

				switch(input)
				{
				case 'R':
					input2 = 4;
					Box(2,11,6,6,6,black on light_red,0,0,0);
					Sleep(500);
					Box(2,11,6,6,6,black on dark_red,0,0,0);

					break;
				case 'B':
					input2 = 3;
					Box(2,17,6,6,6,black on light_cyan,0,0,0);
					Sleep(500);
					Box(2,17,6,6,6,black on dark_cyan,0,0,0);
					break;
				case 'G':
					input2 = 2;
					Box(2,11,12,6,6,black on light_green,0,0,0);
					Sleep(500);
					Box(2,11,12,6,6,black on dark_green,0,0,0);
					break;
				case 'Y':
					input2 = 6;
					Box(2,17,12,6,6,black on light_yellow,0,0,0);
					Sleep(500);
					Box(2,17,12,6,6,black on dark_yellow,0,0,0);
					break;
				default:
					cout << "Please enter R,B,G, or Y." << endl;
					break;
				}
				if(input2 != Simon_Board[ck])
				{
					setcolor();
					gotoXY(30,10);
					cout << "You have gotten the sequence incorrect!";
					gotoXY(30,11);
					cout << "Sequence was:";
					genColors(Simon_Board,round);
					Sleep(2000);
					setcolor();
					gotoXY(30,11);
					cout << "Thank you for playing!";
					gotoXY(30,12);
					cout << "Would you like to try again?(Y/N): ";
					input3 = toupper(_getch());
					if(input3 == 'Y')
					{
						round = 0;
						setcolor();
						for(int c = 0;c < 256; c++)
							Simon_Board[c] = Simon_Color[rand()%4];
						for(int i=0;i<3;i++)
						{
							gotoXY(30,10+i);
							cout << "                                       ";
						}
					}
					else
					{
						ok = false;
					}
				}
				setcolor();
			}
			if(ok)
			{
				gotoXY(30,10);
				cout << "You have won round " << round << "!";
				round++;
				Sleep(1000);
				gotoXY(30,10);
				cout << "                       ";
			}
		}while(round<256 && ok);
	}while (ok);
	return 0;
} 

void Box(int style, int across, int down, int amount, int rows, int f_color, int b_color, int shadow, int shadow_fc, int shadow_bc)
{
	char Shadow[4] = { ' ','\xB0','\xB1','\xB2' };

	char  Style[5][7] = { 
		{' ',' ',' ',' ',' ',' ',' ' },
		{' ','\xDA','\xC4','\xBF','\xB3','\xC0','\xD9'},
		{' ','\xC9','\xCD','\xBB','\xBA','\xC8','\xBC'},
		{' ','\xD5','\xCD','\xB8','\xB3','\xD4','\xBE'},
		{' ','\xD6','\xC4','\xB7','\xBA','\xD3','\xBD'}
	};

	int x;
	string BoxLine(amount-2, Style[style][2]);
	string BoxBody(amount-2, ' ');
	string ShadowLine(amount, Shadow[shadow]);

	gotoXY(across,down);
	setcolor(f_color on b_color);
	cout << Style[style][1] << BoxLine << Style[style][3];
	for (x=1; x<rows; x++)
	{
		gotoXY(across,down+x);
		cout << Style[style][4] << BoxBody << Style[style][4];
		if (shadow)
		{
			setcolor(shadow_fc on shadow_bc);
			cout << Shadow[shadow];
			setcolor(f_color on b_color);
		}
	}
	gotoXY(across,down+rows-1);
	cout << Style[style][5] << BoxLine <<  Style[style][6];
	if (shadow)
	{
		setcolor(shadow_fc on shadow_bc);
		cout << Shadow[shadow];
		gotoXY(across+1,down+rows);
		cout << ShadowLine;
		setcolor(f_color on b_color);
	}
}

void genColors(int Simon_Board[256],int round)
{
	for(int s = 0;s < round;s++)
	{
		switch(Simon_Board[s])
		{
		case 2:
			Box(2,11,12,6,6,black on light_green,0,0,0);
			Sleep(500);
			Box(2,11,12,6,6,black on dark_green,0,0,0);
			break;
		case 3:
			Box(2,17,6,6,6,black on light_cyan,0,0,0);
			Sleep(500);
			Box(2,17,6,6,6,black on dark_cyan,0,0,0);
			break;
		case 4:
			Box(2,11,6,6,6,black on light_red,0,0,0);
			Sleep(500);
			Box(2,11,6,6,6,black on dark_red,0,0,0);
			break;
		case 6:
			Box(2,17,12,6,6,black on light_yellow,0,0,0);
			Sleep(500);
			Box(2,17,12,6,6,black on dark_yellow,0,0,0);
		}
		Sleep(500);
	}
	Sleep(500);
}

void gotoXY(int x, int y) 
{ 
	CursorPosition.X = x; 
	CursorPosition.Y = y; 
	SetConsoleCursorPosition(console,CursorPosition); 
}
Last edited on
Nice, I am now making buttons for the box.
Topic archived. No new replies allowed.