главная|main page

состояние|status

блог|blog

файлы|files

программы|software

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Davydov <lotigara@lotigara.ru>2025-04-12 11:26:25 +0300
committerIvan Davydov <lotigara@lotigara.ru>2025-04-12 11:26:25 +0300
commit8995746812ee29de72d5f79d6b1b0717dee7155b (patch)
tree0c65337e793af7f069313a6ea09e6484d361517e
parent112b1bec3d7f5b6b90812850306f0ade4cc3771d (diff)
Make the game more verbose
-rw-r--r--clicker-ncurses.c33
-rw-r--r--clicker-ncurses.h2
2 files changed, 23 insertions, 12 deletions
diff --git a/clicker-ncurses.c b/clicker-ncurses.c
index 23d3a4d..6c30449 100644
--- a/clicker-ncurses.c
+++ b/clicker-ncurses.c
@@ -1,3 +1,4 @@
+#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -21,6 +22,10 @@ main (void)
/* This fixes the problem of input that shows up */
noecho();
+ /* There should be a delay between clicks
+ 1 s */
+ timeout(1000);
+
/* Place a border with default settings (0 means default) */
border(0, 0, 0, 0, 0, 0, 0, 0);
@@ -28,13 +33,17 @@ main (void)
int sy, sx;
getmaxyx(stdscr, sy, sx);
- /* Place a string onto the window in specified location */
+ /* Place a string onto the window in the center */
char *name = "NCurses clicker";
mvprintw(0, sx / 2 - strlen(name) / 2, name);
char *help = "[ ] - click, [q]uit, [u]pgrade";
mvprintw(sy - 2, sx / 2 - strlen(help) / 2, help);
+ mvprintw(3, 1, "Score:\n");
+ mvprintw(5, 1, "Points by click:\n");
+ mvprintw(7, 1, "Required score to update:\n");
+
/* Refresh our window to include settings above */
refresh();
@@ -50,23 +59,21 @@ main (void)
switch (ch)
{
case ' ':
- set_score(cur_game, cur_game->score + cur_game->click);
+ render_values(cur_game, cur_game->score + cur_game->click, cur_game->click, cur_game->multiplifier);
break;
case 'q':
goto endwin;
case 'u':
if (cur_game->score >= cur_game->click * cur_game->multiplifier)
{
- set_score(cur_game, 0);
- ++cur_game->click;
- ++cur_game->multiplifier;
+ render_values(cur_game, 0, ++cur_game->click, cur_game->multiplifier * 2);
}
break;
}
if (cur_game->score < 0)
{
- set_score(cur_game, 0);
+ render_values(cur_game, 0, cur_game->click, cur_game->multiplifier);
}
}
@@ -74,21 +81,25 @@ main (void)
endwin: endwin();
printf("You have got %d points.\n", cur_game->score);
- /* TODO: deal with valgrind complaints */
+ /* TODO: deal with memory leaks */
free(cur_game);
exit(EXIT_SUCCESS);
}
void
-set_score (struct game *game, int score)
+render_values (struct game *game, int score, int click, int multiplifier)
{
int score_len = snprintf(NULL, 0, "%d", game->score);
- for (int i = 0; i <= score_len; ++i)
+ for (int i = 0; i < score_len; ++i)
{
- mvaddch(3, i + 1, ' ');
+ mvaddch(4, i + 1, ' ');
refresh();
}
game->score = score;
- mvprintw(3, 1, "%d", game->score);
+ game->click = click;
+ game->multiplifier = multiplifier;
+ mvprintw(4, 1, "%d", game->score);
+ mvprintw(6, 1, "%d", game->click);
+ mvprintw(8, 1, "%d", game->multiplifier * game->click);
}
diff --git a/clicker-ncurses.h b/clicker-ncurses.h
index cbaf969..fbc4f54 100644
--- a/clicker-ncurses.h
+++ b/clicker-ncurses.h
@@ -5,4 +5,4 @@ struct game
int score;
};
-void set_score (struct game *game, int score);
+void render_values (struct game *game, int score, int click, int multiplifier);