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