From 00275cef8f965a9d8aee53b6a10dbb37f88c845d Mon Sep 17 00:00:00 2001 From: Artsiom Dzenisiuk Date: Wed, 15 Oct 2025 14:15:01 +0200 Subject: [PATCH] initial commit --- main.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 ++ 2 files changed, 94 insertions(+) create mode 100644 main.c create mode 100644 makefile diff --git a/main.c b/main.c new file mode 100644 index 0000000..96db663 --- /dev/null +++ b/main.c @@ -0,0 +1,92 @@ +#include +#include +#include + +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(); +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..18469f3 --- /dev/null +++ b/makefile @@ -0,0 +1,2 @@ +CFLAGS = -lcurses -std=c23 -Wextra -pedantic -Wall +main: main.c