Rev 1466 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1466 | Rev 1590 | ||
---|---|---|---|
Line 44... | Line 44... | ||
44 | */ |
44 | */ |
45 | #include <errno.h> |
45 | #include <errno.h> |
46 | /* #include <err.h> */ |
46 | /* #include <err.h> */ |
47 | /* #include <fcntl.h> */ |
47 | /* #include <fcntl.h> */ |
48 | /* #include <pwd.h> */ |
48 | /* #include <pwd.h> */ |
49 | /* #include <stdio.h> */ |
49 | #include <stdio.h> |
50 | /* #include <stdlib.h> */ |
50 | /* #include <stdlib.h> */ |
51 | /* #include <string.h> */ |
51 | #include <string.h> |
52 | /* #include <time.h> */ |
52 | /* #include <time.h> */ |
53 | /* #include <term.h> */ |
53 | /* #include <term.h> */ |
54 | /* #include <unistd.h> */ |
54 | /* #include <unistd.h> */ |
55 | /* #include <sys/param.h> */ |
55 | /* #include <sys/param.h> */ |
56 | /* #include <sys/stat.h> */ |
56 | /* #include <sys/stat.h> */ |
Line 74... | Line 74... | ||
74 | 74 | ||
75 | /* static time_t now; */ |
75 | /* static time_t now; */ |
76 | /* static int nscores; */ |
76 | /* static int nscores; */ |
77 | /* static int gotscores; */ |
77 | /* static int gotscores; */ |
78 | /* static struct highscore scores[NUMSPOTS]; */ |
78 | /* static struct highscore scores[NUMSPOTS]; */ |
- | 79 | static struct highscore scores[NUMSPOTS]; |
|
79 | 80 | ||
80 | /* static int checkscores(struct highscore *, int); */ |
81 | /* static int checkscores(struct highscore *, int); */ |
81 | /* static int cmpscores(const void *, const void *); */ |
82 | /* static int cmpscores(const void *, const void *); */ |
82 | /* static void getscores(FILE **); */ |
83 | /* static void getscores(FILE **); */ |
83 | /* static void printem(int, int, struct highscore *, int, const char *); */ |
84 | /* static void printem(int, int, struct highscore *, int, const char *); */ |
84 | /* static char *thisuser(void); */ |
85 | /* static char *thisuser(void); */ |
85 | 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 | } |
|
- | 169 | ||
86 | /* |
170 | /* |
87 | * Read the score file. Can be called from savescore (before showscores) |
171 | * Read the score file. Can be called from savescore (before showscores) |
88 | * or showscores (if savescore will not be called). If the given pointer |
172 | * or showscores (if savescore will not be called). If the given pointer |
89 | * is not NULL, sets *fpp to an open file pointer that corresponds to a |
173 | * is not NULL, sets *fpp to an open file pointer that corresponds to a |
90 | * read/write score file that is locked with LOCK_EX. Otherwise, the |
174 | * read/write score file that is locked with LOCK_EX. Otherwise, the |
Line 342... | Line 426... | ||
342 | * savescore is called at all, for two reasons: |
426 | * savescore is called at all, for two reasons: |
343 | * - Showscores munches the time field. |
427 | * - Showscores munches the time field. |
344 | * - Even if that were not the case, a new score must be recorded |
428 | * - Even if that were not the case, a new score must be recorded |
345 | * before it can be shown anyway. |
429 | * before it can be shown anyway. |
346 | */ |
430 | */ |
- | 431 | /* |
|
347 | void |
432 | void |
348 | showscores(int level) |
433 | showscores(int level) |
349 | { |
434 | { |
350 | return; |
435 | return; |
351 | } |
436 | } |
352 | 437 | */ |
|
353 | /* struct highscore *sp; */ |
438 | /* struct highscore *sp; */ |
354 | /* int i, n, c; */ |
439 | /* int i, n, c; */ |
355 | /* const char *me; */ |
440 | /* const char *me; */ |
356 | /* int levelfound[NLEVELS]; */ |
441 | /* int levelfound[NLEVELS]; */ |
357 | 442 |