Skip to content

Commit c47e9a6

Browse files
committed
Simon:
-Display function finished
1 parent b7b9197 commit c47e9a6

File tree

1 file changed

+57
-54
lines changed

1 file changed

+57
-54
lines changed

Simon/simon.c

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,74 @@ extern void getCursorPosition(int* row, int* col);
1212
typedef unsigned char sshort;
1313

1414
typedef enum ColorButtons {
15+
NO_COLOR = 0,
1516
GREEN = 1,
1617
RED,
1718
YELLOW,
1819
BLUE
1920
}Color;
2021

21-
void display(int button, bool zero, int screenSize[2])
22+
void display(int button, int screenSize[2])
2223
{
2324
setupConsole();
24-
if (zero == true)
25-
{
26-
moveTo(0, 0);
27-
28-
for (int row = 0; row <= screenSize[0]/2 ; row++)
29-
{
30-
setBackgroundColorRGB(30, 50, 40); // shadow green
31-
for (int greenCol = 0; greenCol <= (screenSize[1] / 2) - 1; greenCol++)
32-
printf(" ");
3325

34-
if (screenSize[1] % 2 != 0)
35-
printf(" ");
26+
moveTo(0, 0);
3627

37-
setBackgroundColorRGB(50, 30, 40); // shadow red
38-
for (int rednCol = 0; rednCol <= (screenSize[1] / 2) - 1; rednCol++)
39-
printf(" ");
28+
for (int row = 0; row <= (screenSize[0] / 2) - 2; row++)
29+
{
30+
if (button == GREEN)
31+
setBackgroundColorRGB(0, 150, 0); // bright green
32+
else
33+
setBackgroundColorRGB(15, 60, 15); // shadow green
34+
for (int greenCol = 0; greenCol <= (screenSize[1] / 2) - 1; greenCol++)
35+
printf(" ");
36+
37+
if (button == RED)
38+
setBackgroundColorRGB(150, 30, 40); // bright red
39+
else
40+
setBackgroundColorRGB(70, 30, 30); // shadow red
41+
for (int rednCol = 0; rednCol <= (screenSize[1] / 2) - 1; rednCol++)
42+
printf(" ");
43+
44+
printf("\n");
4045

41-
printf("\n");
42-
}
46+
}
4347

44-
if (screenSize[0] % 2 != 0)
45-
printf("\n");
48+
if (screenSize[0] % 2 != 0)
49+
printf("\n");
4650

47-
for (int row = 0; row <= screenSize[0]/2; row++)
48-
{
51+
for (int row = 0; row <= (screenSize[0] / 2) - 2; row++)
52+
{
53+
if (button == YELLOW)
54+
setBackgroundColorRGB(255, 255, 0); // bright yellow
55+
else
4956
setBackgroundColorRGB(50, 50, 0); // shadow yellow
50-
for (int greenCol = 0; greenCol <= (screenSize[1] / 2) - 1; greenCol++)
51-
printf(" ");
57+
for (int greenCol = 0; greenCol <= (screenSize[1] / 2) - 1; greenCol++)
58+
printf(" ");
5259

53-
if (screenSize[1] % 2 != 0)
54-
printf(" ");
5560

56-
setBackgroundColorRGB(40, 30, 50); // shadow blue
57-
for (int rednCol = 0; rednCol <= (screenSize[1] / 2) - 1; rednCol++)
58-
printf(" ");
59-
60-
printf("\n");
61-
}
61+
if (screenSize[1] % 2 != 0)
62+
printf(" ");
6263

64+
if (button == BLUE)
65+
setBackgroundColorRGB(40, 30, 150); // bright blue
66+
else
67+
setBackgroundColorRGB(15, 15, 60); // shadow blue
68+
for (int rednCol = 0; rednCol <= (screenSize[1] / 2) - 1; rednCol++)
69+
printf(" ");
6370
}
64-
65-
66-
restoreConsoleMode();
71+
restoreConsole();
72+
printf("\n");
6773
}
6874

6975
void rng(int* sequence, int level)
7076
{
71-
unsigned int sequenceSize = level;
72-
bool repetion;
73-
sequence[sequenceSize - 2] = 0;
74-
for (int count1 = 0; count1 < sequence[sequenceSize - 1]; count1++)
75-
{
76-
sequence[count1] = 1 + rand() % 4;
77-
for (int count2 = 0; count2 < count1; count2++)
78-
{
79-
if (sequence[count2] == sequence[count1])
80-
repetion = true;
81-
while (repetion == 1)
82-
{
83-
sequence[count1] = 1 + rand() % 9;
84-
if (sequence[count2] != sequence[count1])
85-
repetion = false;
86-
}
87-
}
88-
}
77+
sequence[level - 1] = 1 + rand() % 4;
8978
}
9079

9180
int main(int argc, char** argv)
9281
{
93-
int level = 2;
82+
int level = 1;
9483
int windowSize[2];
9584
sshort sequence[4000];
9685
char trashcan[10];
@@ -114,7 +103,21 @@ int main(int argc, char** argv)
114103
getCursorPosition(&windowSize[0], &windowSize[1]);
115104
clearScreenToTop();
116105
restoreConsoleMode();
117-
display(1, true, windowSize);
106+
display(NO_COLOR, windowSize);
107+
fgets(trashcan, 5, stdin);
108+
109+
display(GREEN, windowSize);
110+
fgets(trashcan, 5, stdin);
111+
112+
display(RED, windowSize);
113+
fgets(trashcan, 5, stdin);
114+
115+
display(YELLOW, windowSize);
116+
fgets(trashcan, 5, stdin);
117+
118+
display(BLUE, windowSize);
119+
fgets(trashcan, 5, stdin);
120+
118121
resetColor();
119122
break;
120123
}

0 commit comments

Comments
 (0)