-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu.cpp
More file actions
136 lines (115 loc) · 5.89 KB
/
menu.cpp
File metadata and controls
136 lines (115 loc) · 5.89 KB
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
#include "menu.h"
#include "misc.h"
#include <iostream>
void printMenu() {
clearScreen();
std::cout << "\nConway's game of life beta 0.6.9" << std::endl;
std::cout << "\nMade by ";
printInColor("Andrea Scartazza", Color::red);
std::cout << " & ";
printInColor("Christian Canossa", Color::green);
// Logo in ascii art
printInColor(
"\n\n ________ ________ ________ ___ __ ________ "
"___ ___ ________ \n|\\ "
"____\\ |\\ __ \\ |\\ ___ \\ |\\ \\ |\\ \\ |\\ __ \\ "
" |\\ \\ / /||\\ ____\\ \n\\ \\ "
" \\___| \\ \\ \\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\ \\ \\ \\\\ \\ "
" \\_\\ \\ \\ \\ \\/ / /\\ \\ \\___|_ "
" \n \\ \\ \\ \\ \\ \\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\ "
"__\\ \\ \\\\ \\ __ \\ \\ \\ / / \\ \\_____ \\ "
" \n \\ \\ \\____ \\ \\ \\_\\ \\\\ \\ \\\\ \\ "
"\\\\ \\ \\_\\ \\_\\ \\\\ \\ \\ \\ \\ \\/ / / \\|____|\\ "
"\\ \n \\ \\_______\\\\ \\_______\\\\ "
"\\__\\\\ \\__\\\\ \\____________\\\\ \\__\\ \\__\\ __/ / / "
"____\\_\\ \\ \n \\|_______| "
"\\|_______| \\|__| \\|__| \\|____________| \\|__|\\|__||\\___/ / "
" |\\_________\\ \n "
" \\|___|/ "
"\\|_________| \n "
" "
" \n "
" "
" \n ________ ________ _____ ______ _______ "
"________ ________ ___ ___ ________ _______ "
"\n|\\ ____\\ |\\ __ \\ |\\ _ _ \\ |\\ ____\\ |\\ "
" __ \\ |\\ _____\\ |\\ \\ |\\ \\ |\\ _____\\|\\ ____\\ "
" \n\\ \\ \\___| \\ \\ \\_\\ \\\\ \\ \\\\\\ \\ \\ \\\\ \\ \\ "
"_ \\ \\ \\ \\ \\\\ \\ \\__/ \\ \\ \\ \\ \\ \\\\ "
"\\ \\__/ \\ \\ \\ _ \n \\ \\ \\ ___\\ \\ __ \\\\ \\ "
"\\\\|__| \\ \\\\ \\ _| __ \\ \\ \\ \\ \\\\ \\ __\\ "
"\\ \\ \\ \\ \\ \\\\ \\ __\\ \\ \\ _| __ \n \\ \\ \\|\\ "
"\\\\ \\ \\ \\ \\\\ \\ \\ \\ \\ \\\\ \\ \\__\\ \\ \\ \\ "
"\\_\\ \\\\ \\ \\_| \\ \\ \\____ \\ \\ \\\\ \\ \\_| \\ \\ "
"\\__\\ \\ \n \\ \\_______\\\\ \\__\\ \\__\\\\ \\__\\ \\ \\__\\\\ "
"\\_______\\ \\ \\_______\\\\ \\__\\ \\ \\_______\\\\ "
"\\__\\\\ \\__\\ \\ \\_______\\\n \\|_______| \\|__|\\|__| "
"\\|__| \\|__| \\|_______| \\|_______| \\|__| "
"\\|_______| \\|__| \\|__| \\|_______|\n\n",
Color::yellow);
}
void printOptions() {
std::cout << "1) Play" << std::endl;
std::cout << "2) Rules" << std::endl;
std::cout << "3) Options" << std::endl;
std::cout << "4) Quit\n" << std::endl;
printInColor("Select: ", Color::green);
}
void printRules() {
clearScreen();
printPagedText(
"Conway's Game of Life isn't really a game: there are no players and "
"no concept of winning or losing.\nConway's \"simulation\" is a "
"cellular automaton that demonstrates how, from a few simple rules, "
"life-like behaviour can be simulated.\n\nThis idea was then expanded "
"upon and explored in different contexts like, for example:\n\n1) In "
"3D\n2) Using different kinds of \"cells\"\n3) Using a different set "
"of rules");
clearScreen();
printPagedText(
"The game updates one \"step\" at a time. To determine the state of a "
"cell in the next step you must know:\n\n1) Its current state\n2) The "
"state of neighbouring cells.\n\nThis game relies on the execution of "
"the following three rules:\n\n1) A 'dead' cell surrounded by exactly "
"3 'living' cells will turn alive. (Rule of birth);\n2) A 'living' "
"cell surrouned by 2 or 3 other 'living' cells will stay alive (Rule "
"of survival);\n3) In all other cases, the cell will die (Rule of "
"isolation and Rule of overpopulation).");
clearScreen();
printInColor("\nControls:", Color::green);
printPagedText("Use the arrow keys to select a cell\nUse the space bar to "
"flip the state of the currently selected cell\nPress any "
"other key to start the simulation!");
}
void editOptions(OptionsStruct &options) {
unsigned short selection;
while (true) {
clearScreen();
printMenu();
std::cout << "1) Grid dimensions" << std::endl;
std::cout << "2) Update rate" << std::endl;
std::cout << "3) Close this menu\n" << std::endl;
printInColor("Select: ", Color::green);
std::cin >> selection;
std::cout << std::endl;
switch (selection) {
case 1:
std::cout << "Input desired grid dimensions (default: 100 50): ";
std::cin >> options.sizeX;
std::cin >> options.sizeY;
if (options.sizeX < 1)
options.sizeX = 1;
if (options.sizeY < 1)
options.sizeY = 1;
break;
case 2:
std::cout << "Input how many milliseconds the game should wait "
"before printing a new frame (default: 30): ";
std::cin >> options.frameWait;
break;
case 3:
return;
break;
}
}
}