initial commit
This commit is contained in:
92
main.c
Normal file
92
main.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <curses.h>
|
||||
|
||||
struct crypto_coin {
|
||||
const char *name;
|
||||
const char *description;
|
||||
double prices[30];
|
||||
};
|
||||
|
||||
enum game_state {
|
||||
GAME_BEGIN,
|
||||
GAME_IDLE,
|
||||
GAME_BUY,
|
||||
GAME_SELL,
|
||||
GAME_END,
|
||||
};
|
||||
|
||||
struct game {
|
||||
enum game_state state;
|
||||
int bank;
|
||||
int time;
|
||||
struct crypto_coin coin;
|
||||
};
|
||||
|
||||
void game_draw(struct game *g)
|
||||
{
|
||||
mvaddstr(0, 0, g->coin.name);
|
||||
mvaddstr(1, 0, "-----------------");
|
||||
mvaddstr(2, 0, g->coin.description);
|
||||
|
||||
char buf[50];
|
||||
mvaddstr(3, 0, "You have: ");
|
||||
sprintf(buf, "%i dollars.", g->bank);
|
||||
mvaddstr(3, 15, buf);
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
mvaddch(i+5, 0, '|');
|
||||
}
|
||||
|
||||
for (int i = 0; i < g->time; i++) {
|
||||
color_set(1, NULL);
|
||||
mvaddch(20 - g->coin.prices[i]+5, i+1, '-');
|
||||
for (int j = 20 - g->coin.prices[i] + 1; j < 20; j++) {
|
||||
color_set(2, NULL);
|
||||
mvaddch(j+5, i+1, ' ');
|
||||
}
|
||||
}
|
||||
|
||||
g->time++;
|
||||
refresh();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
initscr();
|
||||
start_color();
|
||||
init_pair(1, COLOR_BLACK, COLOR_RED);
|
||||
init_pair(2, COLOR_BLACK, COLOR_GREEN);
|
||||
cbreak();
|
||||
noecho();
|
||||
nonl();
|
||||
intrflush(stdscr, FALSE);
|
||||
keypad(stdscr, TRUE);
|
||||
clear();
|
||||
refresh();
|
||||
|
||||
struct game game = {
|
||||
.state = GAME_BEGIN,
|
||||
.bank = 1000,
|
||||
.time = 0,
|
||||
.coin = (struct crypto_coin) {
|
||||
.name = "BitCoin",
|
||||
.description = "A fucking scam.",
|
||||
.prices = {
|
||||
10, 11, 12, 12, 12, 12, 12,
|
||||
13, 13, 13, 11, 11, 10, 10,
|
||||
9, 9, 10, 10, 11, 11, 11, 12,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
game_draw(&game);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
refresh();
|
||||
|
||||
sleep(10);
|
||||
endwin();
|
||||
}
|
||||
Reference in New Issue
Block a user