Skip to content

Commit 2f72a24

Browse files
committed
new: black screen pause start option
1 parent 45c9019 commit 2f72a24

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,34 @@ void start(int argc, char *argv[])
7171
static struct option const long_options[] = {
7272
/* name, has_arg, *flag, chr */
7373
{ "nocolor", 0, 0, 'c' },
74+
{ "bsp", 0, 0, 'b' },
7475
{ "help", 0, 0, 'h' },
7576
{ 0, 0, 0, 0 }
7677
};
7778

79+
int to_options = 0; // like black screen pause
80+
7881
for (;;) {
7982
int option_index;
80-
switch (getopt_long(argc, argv, "?hc", long_options, &option_index)) {
83+
switch (getopt_long(argc, argv, "?hcb", long_options, &option_index)) {
8184
case -1:
8285
goto _end_of_opts;
8386

8487
case 'c':
8588
con_colors_enable(0);
8689
break;
8790

91+
case 'b':
92+
to_options |= TO_BLACK_SCREEN_PAUSE;
93+
break;
94+
8895
case 'h':
8996
case '?':
9097
con_put(
9198
"Usage: %s <options>\n\n\
9299
options:\n\
93100
-c, --nocolor\t: disable ANSI colors;\n\
101+
-b, --bsp\t: enable black screen pause;\n\
94102
-h\t\t: print this help and exit.\n\n", get_path_filename(argv[0]));
95103
return;
96104
}
@@ -104,6 +112,6 @@ options:\n\
104112

105113
io_atexit(free_all);
106114

107-
tetris_init(&ntet, 0, 0);
115+
tetris_init(&ntet, 0, 0, to_options);
108116
tetris_start(&ntet);
109117
}

tetris.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static void tetris_pause(tetris_t *self)
3131
{
3232
io_timer_set_timeout(self->timer, (self->paused = !self->paused) ? -1 : 1000);
3333
if (self->paused) {
34-
//con_cls();
34+
if (self->options & TO_BLACK_SCREEN_PAUSE)
35+
con_cls();
3536
} else {
3637
tetris_refresh(self);
3738
}
@@ -67,7 +68,7 @@ static void tetris_key_handler(void *p, char const *seq, int code)
6768

6869

6970
/* -------------------------------------------------------------------------- */
70-
void tetris_init(tetris_t *self, int left, int top)
71+
void tetris_init(tetris_t *self, int left, int top, int options)
7172
{
7273
score_init(&self->score, left + 5, top + 4);
7374
board_init(&self->game, left + 27, top + 2, 10, 20, " .");
@@ -78,6 +79,7 @@ void tetris_init(tetris_t *self, int left, int top)
7879
self->timer = NULL;
7980
io_key_on(tetris_key_handler, self);
8081
self->paused = 0;
82+
self->options = options;
8183
}
8284

8385
/* -------------------------------------------------------------------------- */

tetris.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
enum { KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_DROP, KEY_PAUSE, KEY_QUIT };
55

6+
enum { TO_BLACK_SCREEN_PAUSE = 1 };
7+
68
typedef
79
struct tetris {
810
board_t game;
@@ -14,9 +16,10 @@ struct tetris {
1416
io_timer_t *timer;
1517
int period; // timer period;
1618
int paused;
19+
int options;
1720
} tetris_t;
1821

1922

20-
void tetris_init(tetris_t *self, int left, int top);
23+
void tetris_init(tetris_t *self, int left, int top, int options);
2124
void tetris_free(tetris_t *self);
2225
void tetris_start(tetris_t *self);

0 commit comments

Comments
 (0)