158,6 → 158,93 |
srandom(tv.tv_sec + tv.tv_usec / 100000); |
} |
|
static void tetris_scores(int firstgame) |
{ |
} |
|
static void tetris_menu_draw(int level) |
{ |
clear_screen(); |
moveto(5,10); |
puts("Tetris\n\n"); |
|
moveto(8,10); |
printf("Level = %d (press keys 1 - 9 to change)",level); |
moveto(9,10); |
printf("Preview is %s (press 'p' to change)", (showpreview?"on ":"off")); |
moveto(12,10); |
printf("Press 'h' to show hiscore table."); |
moveto(13,10); |
printf("Press 's' to start game."); |
moveto(14,10); |
printf("Press 'q' to quit game."); |
moveto(20,10); |
printf("In game controls:"); |
moveto(21,0); |
puts(key_msg); |
} |
|
static int tetris_menu(int *level) |
{ |
static int firstgame = 1; |
int i; |
/* if (showpreview == 0) |
(void)printf("Your score: %d point%s x level %d = %d\n", |
score, score == 1 ? "" : "s", level, score * level); |
else { |
(void)printf("Your score: %d point%s x level %d x preview penalty %0.3f = %d\n", |
score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, |
(int)(score * level * PRE_PENALTY)); |
score = score * PRE_PENALTY; |
} |
savescore(level); |
|
showscores(level); |
|
printf("\nHit 's' to new game, 'q' to quit.\n"); |
*/ |
tetris_menu_draw(*level); |
while (1) { |
|
i = getchar(); |
|
switch(i) { |
case 'p': |
showpreview = !showpreview; |
moveto(9,21); |
if (showpreview) |
printf("on "); |
else |
printf("off"); |
|
break; |
case 'h': |
showscores(firstgame); |
tetris_menu_draw(*level); |
break; |
case 's': |
firstgame = 0; |
return 1; |
case 'q': |
return 0; |
case '1': |
case '2': |
case '3': |
case '4': |
case '5': |
case '6': |
case '7': |
case '8': |
case '9': |
*level = i - '0'; |
moveto(8,18); |
printf("%d", *level); |
break; |
} |
} |
|
} |
|
int |
main(int argc, char *argv[]) |
{ |
174,7 → 261,8 |
// egid = getegid(); |
// setegid(gid); |
|
classic = showpreview = 0; |
classic = 0; |
showpreview = 1; |
|
/* while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */ |
/* switch(ch) { */ |
232,8 → 320,13 |
"%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", |
key_write[0], key_write[1], key_write[2], key_write[3], |
key_write[4], key_write[5]); |
newgame: |
|
scr_init(); |
initscores(); |
while (tetris_menu(&level)) { |
|
|
scr_clear(); |
setup_board(); |
|
srandomdev(); |
338,31 → 431,9 |
} |
|
scr_clear(); |
scr_end(); |
|
if (showpreview == 0) |
(void)printf("Your score: %d point%s x level %d = %d\n", |
score, score == 1 ? "" : "s", level, score * level); |
else { |
/* (void)printf("Your score: %d point%s x level %d x preview penalty %0.3f = %d\n", */ |
/* score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, */ |
/* (int)(score * level * PRE_PENALTY)); */ |
/* score = score * PRE_PENALTY; */ |
insertscore(score, level); |
} |
savescore(level); |
|
showscores(level); |
|
printf("\nHit 's' to new game, 'q' to quit.\n"); |
|
|
while (i = getchar()) { |
if (i == 's') |
goto newgame; |
if (i == 'q') |
break; |
} |
|
scr_clear(); |
printf("\n\n\n\t\tGame over.\n"); |
/* |
370,6 → 441,7 |
if (i == EOF) |
break |
*/ |
scr_end(); |
exit(0); |
} |
|