Changeset 3a180ad in mainline
- Timestamp:
- 2009-04-08T20:00:38Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ccf814f
- Parents:
- 8be693b
- Location:
- uspace/app/tetris
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/scores.c
r8be693b r3a180ad 56 56 /* #include <stdlib.h> */ 57 57 #include <string.h> 58 #include <kbd/kbd.h> 59 #include <kbd/keycode.h> 60 #include <stdlib.h> 58 61 /* #include <time.h> */ 59 62 /* #include <term.h> */ … … 123 126 { 124 127 int i,j; 125 int key;126 128 size_t off; 129 kbd_event_t ev; 127 130 128 131 clear_screen(); … … 130 133 puts("Insert your name: "); 131 134 strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME); 132 i = 6; 135 i = 6; off = 6; 133 136 134 137 moveto(10 , 28); 135 138 printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); 136 key = getchar(); 137 while(key != '\n') { 138 if (key == '\b') { 139 if (i > 0) 140 scores[NUMSPOTS - 1].hs_name[--i] = '\0'; 141 } else { 142 if (i < (MAXLOGNAME - 1)) 143 scores[NUMSPOTS - 1].hs_name[i++] = key; 144 scores[NUMSPOTS - 1].hs_name[i] = '\0'; 139 140 while (1) { 141 fflush(stdout); 142 if (kbd_get_event(&ev) != EOK) 143 exit(1); 144 145 if (ev.type == KE_RELEASE) 146 continue; 147 148 if (ev.key == KC_ENTER || ev.key == KC_NENTER) 149 break; 150 151 if (ev.key == KC_BACKSPACE) { 152 if (i > 0) { 153 wchar_t uc; 154 155 --i; 156 while (off > 0) { 157 --off; 158 size_t otmp = off; 159 uc = str_decode(scores[NUMSPOTS - 1].hs_name, 160 &otmp, STR_BOUNDS(MAXLOGNAME) + 1); 161 if (uc != U_SPECIAL) 162 break; 163 } 164 165 scores[NUMSPOTS - 1].hs_name[off] = '\0'; 166 } 167 } else if (ev.c != '\0') { 168 if (i < (MAXLOGNAME - 1)) { 169 if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, 170 &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { 171 ++i; 172 } 173 scores[NUMSPOTS - 1].hs_name[off] = '\0'; 174 } 145 175 } 146 176 147 177 moveto(10 , 28); 148 178 printf("%s%.*s",scores[NUMSPOTS - 1].hs_name,MAXLOGNAME-i,"........................................"); 149 150 key = getchar();151 179 } 152 180 -
uspace/app/tetris/scores.h
r8be693b r3a180ad 46 46 */ 47 47 #include <sys/time.h> 48 #include <string.h> 49 48 50 #define MAXLOGNAME 16 49 51 struct highscore { 50 char hs_name[ MAXLOGNAME+ 1]; /* login name */52 char hs_name[STR_BOUNDS(MAXLOGNAME) + 1]; /* login name */ 51 53 int hs_score; /* raw score */ 52 54 int hs_level; /* play level */
Note:
See TracChangeset
for help on using the changeset viewer.