Changeset d4b9d28 in mainline
- Timestamp:
- 2009-06-23T18:33:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7b47fa2
- Parents:
- 52e4f52
- Location:
- uspace/app/tetris
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/scores.c
r52e4f52 rd4b9d28 197 197 } 198 198 199 int loadscores(void) 200 { 201 FILE *f; 202 size_t cnt; 203 int rc; 204 205 f = fopen("/tetris.sco", "rb"); 206 if (f == NULL) 207 return ENOENT; 208 209 cnt = fread(scores, sizeof(struct highscore), NUMSPOTS, f); 210 rc = fclose(f); 211 212 if (cnt != NUMSPOTS || rc != 0) 213 return EIO; 214 215 return EOK; 216 } 217 218 void savescores(void) 219 { 220 FILE *f; 221 size_t cnt; 222 int rc; 223 224 f = fopen("/tetris.sco", "wb"); 225 cnt = fwrite(scores, sizeof(struct highscore), NUMSPOTS, f); 226 rc = fclose(f); 227 228 if (cnt != NUMSPOTS || rc != 0) 229 printf("Error saving score table\n"); 230 } 231 199 232 /** @} 200 233 */ -
uspace/app/tetris/scores.h
r52e4f52 rd4b9d28 65 65 extern void initscores(void); 66 66 extern void insertscore(int score, int level); 67 extern int loadscores(void); 68 extern void savescores(void); 67 69 68 70 /** @} -
uspace/app/tetris/tetris.c
r52e4f52 rd4b9d28 50 50 #include <sys/types.h> 51 51 #include <err.h> 52 #include <errno.h> 52 53 #include <stdio.h> 53 54 #include <stdlib.h> … … 207 208 break; 208 209 case 'h': 210 loadscores(); 209 211 showscores(firstgame); 210 212 tetris_menu_draw(*level); … … 298 300 299 301 scr_init(); 300 initscores(); 302 if (loadscores() != EOK) 303 initscores(); 304 301 305 while (tetris_menu(&level)) { 302 306 fallrate = 1000000 / level; … … 416 420 417 421 scr_clear(); 422 loadscores(); 418 423 insertscore(score, level); 424 savescores(); 419 425 score = 0; 420 426 }
Note:
See TracChangeset
for help on using the changeset viewer.