-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
174 lines (151 loc) · 4.75 KB
/
main.c
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
#include "main.h"
#include "draw_otazky.h"
unsigned long long t_now=0, t_lastRender=0, t_lastStonks=0;
struct app app;
struct player player;
struct stocks stocks;
struct cursor cursor;
struct state* stonksState;
int editMode;
int enteredValue = 0;
int question = 0;
struct Otazka otazka[10];
int calculateNetWorth()
{
int ret = player.freeCash;
return 0;
}
int main()
{
signal(SIGINT, exit_handler);
app.consoleHeight = getConsoleHeight();
app.consoleWidth = getConsoleWidth();
app.targetFPS = 15;
app.state = 2; // otazky
player.freeCash = 1000;
player.netWorth = 0;
cursor.x = 0;
cursor.y = 0;
editMode = 0;
//random init
pcg32_srandom((uint64_t) time(0), (uint64_t) time(0)/2);
//APP INIT
initTermios(0);
// INIT otazky
otazky();
/// STONKS INIT
stonksState = initState();
for(int i = 0; i < 5; i++)
{
updateInstrument(stonksState, i, (float)(50+pcg32_boundedrand(100)));
setDirection(stonksState, i, ((i % 2) * 2) - 1);
}
setRiskLevel(stonksState, 0, CONSERVATIVE);
setRiskLevel(stonksState, 1, BALANCED);
setRiskLevel(stonksState, 2, DYNAMIC);
setRiskLevel(stonksState, 3, CONSERVATIVE);
setRiskLevel(stonksState, 4, BALANCED);
setVolatility(stonksState, 0, HIGH);
setVolatility(stonksState, 1, LOW);
setVolatility(stonksState, 2, MEDIUM);
setVolatility(stonksState, 3, MEDIUM);
setVolatility(stonksState, 4, HIGH);
//GAME LOOP
while(app.state==1 || app.state == 2 || app.state == 3)
{
if(kbhit())
{
char key = parseKey();
if(editMode)
{
if(key == 'n')
{
if(cursor.x == 0)
{
buyInstrumentMoney(stonksState, cursor.y, (float)enteredValue);
}
if(cursor.x == 1)
{
sellInstrumentMoney(stonksState, cursor.y, (float)enteredValue);
}
editMode = 0;
}
else if(key == '`')
{
enteredValue /= 10;
}
if(enteredValue < 10000)
{
if((key >= '0') && (key <= '9'))
enteredValue = (enteredValue * 10) + (key - '0');
}
}
else
{
int ROWS = 5;
if (app.state == 2)
ROWS = 3;
switch (key)
{
case 'w':
cursor.y = (cursor.y - 1) % ROWS;
if(cursor.y < 0) cursor.y = 4;
break;
case 's':
cursor.y = (cursor.y + 1) % ROWS;
break;
case 'a':
cursor.x = (cursor.x - 1) % 3;
if(cursor.x < 0) cursor.x = 2;
break;
case 'd':
cursor.x = (cursor.x + 1) % 3;
break;
case 'n':
if(app.state == 3) // graf
{
app.state = 1;
}
else if((app.state == 1) && (cursor.x == 2)) // chcem graf
{
app.state = 3;
}
else if(app.state == 2){
if (cursor.y == otazka[question].correct)
question++;
if (question>3)
app.state = 1;
}
else
{
editMode = (editMode + 1) % 2;
enteredValue = 0;
}
break;
}
}
}
usElapsed(&t_now);
if(t_now >= t_lastRender+(1e6/(app.targetFPS*1.0))) ///Draw :)
{
/// DRAW
if (app.state == 2)
draw_otazky();
/// GRAPH
else if (app.state == 3)
draw_graph();
else
draw();
t_lastRender = t_now;
app.cyclesPerFrame=0;
}
if(t_now >= t_lastStonks+(1e6)) ///Draw :)
{
updateInstruments(stonksState);
t_lastStonks = t_now;
}
else app.cyclesPerFrame++;
msDelay(1); ///Let the CPU sleep for a bit
}
exit_handler(0);
}