Skip to content

Commit 3fc7fac

Browse files
committed
Simon:
-RNG function created -Requirements for computing are almost ready -Deciding how will show the screen
1 parent 85d3d9f commit 3fc7fac

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Simon/simon.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stdbool.h>
4+
#include <time.h>
5+
#include "ansi_escapes.h"
6+
7+
extern void setupConsole(void);
8+
extern void restoreConsoleMode(void);
9+
extern void restoreConsole(void);
10+
extern void getCursorPosition(int* row, int* col);
11+
12+
typedef enum ColorButtons {
13+
GREEN = 1,
14+
RED,
15+
YELLOW,
16+
BLUE
17+
}Color;
18+
19+
void rng(int* sequence, int level)
20+
{
21+
unsigned int sequenceSize = level;
22+
bool repetion;
23+
sequence[sequenceSize - 2] = 0;
24+
for (int count1 = 0; count1 < sequence[sequenceSize - 1]; count1++)
25+
{
26+
sequence[count1] = 1 + rand() % 4;
27+
for (int count2 = 0; count2 < count1; count2++)
28+
{
29+
if (sequence[count2] == sequence[count1])
30+
repetion = true;
31+
while (repetion == 1)
32+
{
33+
sequence[count1] = 1 + rand() % 9;
34+
if (sequence[count2] != sequence[count1])
35+
repetion = false;
36+
}
37+
}
38+
}
39+
}
40+
41+
int main(int argc, char** argv)
42+
{
43+
int level = 2;
44+
int windowSize[2];
45+
int sequence[4000];
46+
char trashcan[10];
47+
48+
srand(time(NULL));
49+
50+
printf("Starting Simon. Do you wish to:\n(P) play now\nor \n (T)see the tutorial?\n");
51+
fgets(trashcan, 5, stdin);
52+
53+
if (trashcan[0] == 'T')
54+
{
55+
//teach how to play
56+
}
57+
58+
if (trashcan[0] == 'P')
59+
{
60+
for (bool replay = true; replay == true;)
61+
{
62+
clearScreenToBottom();
63+
getCursorPosition(&windowSize[0], &windowSize[1]);
64+
clearScreenToTop();
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)