#include #include #include #include #include #include #include struct chart { size_t length; double *prices; }; struct coin { const char *name; const char *description; struct chart chart; }; struct chart new_chart(size_t length) { double *prices = malloc(length * sizeof(double)); prices[0] = 20; for (size_t i = 1; i < length; i++) { prices[i] = prices[i - 1] + (rand() % 3 - 1.5); } return (struct chart) { .length = length, .prices = prices }; } enum game_state { GAME_BEGIN, GAME_IDLE, GAME_BUY, GAME_SELL, GAME_END, }; struct button { char *name; size_t width; size_t height; struct button *next; }; struct button *new_button(char *name, size_t width, size_t height) { struct button *button = malloc(sizeof(struct button)); button->name = name; button->width = width; button->height = height; button->next = NULL; return button; } struct game { enum game_state state; int bank; struct coin coin; struct button *button; }; void draw_box(size_t x, size_t y, size_t width, size_t height) { mvaddch(y, x, '+'); mvaddch(y + height - 1, x, '+'); mvaddch(y + height - 1, x + width - 1, '+'); mvaddch(y, x + width - 1, '+'); for (size_t i = 1; i < height - 1; i++) { mvaddch(y + i, x, '|'); } for (size_t i = 1; i < height - 1; i++) { mvaddch(y + i, x + width - 1, '|'); } for (size_t i = 1; i < width - 1; i++) { mvaddch(y, x + i, '-'); } for (size_t i = 1; i < width - 1; i++) { mvaddch(y + height - 1, x + i, '-'); } } void draw_button(struct button *b, size_t x, size_t y) { draw_box(x, y, b->width, b->height); mvaddstr(y + b->height / 2, x + b->width / 2 - strlen(b->name) / 2, b->name); } void draw_chart(struct chart *chart, size_t x, size_t y) { draw_box(x - 1, y - 1, (chart->length * 2) + 8, 23); for (size_t i = 0; i < chart->length; i++) { for (size_t j = 0; j < chart->prices[i]; j++) { mvaddch(30 - (y + j), x + (i * 2), '?'); } } struct button *buy = new_button("buy", 20, 5); struct button *sell = new_button("sell", 20, 5); struct button *scam = new_button("scam", 20, 5); attron(COLOR_PAIR(1)); draw_button(buy, 4, 28); attroff(COLOR_PAIR(1)); attron(COLOR_PAIR(2)); draw_button(sell, 28, 28); attroff(COLOR_PAIR(2)); attron(COLOR_PAIR(3)); draw_button(scam, 52, 28); attroff(COLOR_PAIR(3)); } void draw_game(struct game *game) { clear(); mvaddstr(0, 0, game->coin.name); mvaddstr(1, 0, game->coin.description); draw_chart(&game->coin.chart, 5, 5); refresh(); } int main(void) { srand(time(NULL)); initscr(); start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); cbreak(); noecho(); nonl(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); clear(); refresh(); struct game game = { .state = GAME_BEGIN, .bank = 1000, .coin = (struct coin) { .name = "Bitcoin", .description = "A fucking scam.", .chart = new_chart(30) } }; draw_game(&game); refresh(); sleep(300); endwin(); }