Changeset 9996ed5 in mainline for tetris/scores.c
- Timestamp:
- 2006-06-05T20:40:44Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e9073f2
- Parents:
- 0aa024b1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tetris/scores.c
r0aa024b1 r9996ed5 47 47 /* #include <fcntl.h> */ 48 48 /* #include <pwd.h> */ 49 /* #include <stdio.h> */ 49 #include <stdio.h> 50 50 /* #include <stdlib.h> */ 51 /* #include <string.h> */ 51 #include <string.h> 52 52 /* #include <time.h> */ 53 53 /* #include <term.h> */ … … 77 77 /* static int gotscores; */ 78 78 /* static struct highscore scores[NUMSPOTS]; */ 79 static struct highscore scores[NUMSPOTS]; 79 80 80 81 /* static int checkscores(struct highscore *, int); */ … … 83 84 /* static void printem(int, int, struct highscore *, int, const char *); */ 84 85 /* static char *thisuser(void); */ 86 87 void showscores(int firstgame) 88 { 89 int i; 90 91 clear_screen(); 92 moveto(10, 0); 93 printf("\tRank \tLevel \tName\t points\n"); 94 printf("\t========================================================\n"); 95 for (i = 0; i < NUMSPOTS - 1; i++) { 96 printf("\t%6d %6d %-16s %20d\n", i+1, scores[i].hs_level, scores[i].hs_name, scores[i].hs_score); 97 } 98 if (!firstgame) { 99 printf("\t========================================================\n"); 100 printf("\t Last %6d %-16s %20d\n", scores[NUMSPOTS - 1].hs_level, scores[NUMSPOTS - 1].hs_name, scores[NUMSPOTS - 1].hs_score); 101 } 102 printf("\n\n\n\n\tPress any key to return to main menu."); 103 getchar(); 104 } 105 106 /** Copy from hiscore table score with index src to dest 107 * 108 */ 109 static void copyhiscore(int dest, int src) 110 { 111 strcpy(scores[dest].hs_name, scores[src].hs_name); 112 scores[dest].hs_score = scores[src].hs_score; 113 scores[dest].hs_level = scores[src].hs_level; 114 } 115 116 void insertscore(int score, int level) 117 { 118 int i,j; 119 int key; 120 121 122 clear_screen(); 123 moveto(10 , 10); 124 puts("Insert your name: "); 125 strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME); 126 i = 6; 127 128 moveto(10 , 28); 129 printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); 130 key = getchar(); 131 while(key != '\n') { 132 if (key == '\b') { 133 if (i > 0) 134 scores[NUMSPOTS - 1].hs_name[--i] = '\0'; 135 } else { 136 if (i < (MAXLOGNAME - 1)) 137 scores[NUMSPOTS - 1].hs_name[i++] = key; 138 scores[NUMSPOTS - 1].hs_name[i] = '\0'; 139 } 140 141 moveto(10 , 28); 142 printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); 143 144 key = getchar(); 145 } 146 147 scores[NUMSPOTS - 1].hs_score = score; 148 scores[NUMSPOTS - 1].hs_level = level; 149 150 i = NUMSPOTS-1; 151 while ((i > 0) && (scores[i - 1].hs_score < score)) 152 i--; 153 154 for (j = NUMSPOTS - 2; j > i; j--) { 155 copyhiscore(j,j-1); 156 } 157 copyhiscore(i, NUMSPOTS - 1); 158 } 159 160 void initscores(void) 161 { 162 int i; 163 for(i = 0; i < NUMSPOTS; i++) { 164 strncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME); 165 scores[i].hs_score = (NUMSPOTS - i) * 200; 166 scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1); 167 } 168 } 85 169 86 170 /* … … 345 429 * before it can be shown anyway. 346 430 */ 431 /* 347 432 void 348 433 showscores(int level) … … 350 435 return; 351 436 } 352 437 */ 353 438 /* struct highscore *sp; */ 354 439 /* int i, n, c; */
Note:
See TracChangeset
for help on using the changeset viewer.