1010
Check-in [a0ca976006]
Not logged in
Public Repositories
mwm's Repositories

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Finish up the help system.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a0ca976006ac4ccbd463ce13c68f878050143d93
User & Date: mwm 2016-11-07 11:47:35
Context
2016-11-07
12:00
Update the docs check-in: e0deaf568b user: mwm tags: trunk
11:47
Finish up the help system. check-in: a0ca976006 user: mwm tags: trunk
2016-11-06
15:24
Generalize the help system before rewriting it. check-in: dc570350e4 user: mwm tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tiny-1010.ino.

125
126
127
128
129
130
131

132
133
134








135
136
137
138
139
140
141
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
282
283
284
285
286
287
288
289




290
291
292
293
294
295
296
...
346
347
348
349
350
351
352
353




354
355
356
357
358
359
360
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
...
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
     {2, 2, fours[3]},	// small 2x2 corners
     {2, 2, fours[4]},
     {2, 2, fours[5]},
     {2, 2, fours[6]},
};



const char *help[] = {
     "   Selecting\n\30\31: Change shape\n\32: Use shape\nA: Fit & use shape\nB: Pause",
     "  Moving Shape\n\30\31\33\32: Move shape\n\33: Deselect shape\nA: Place shape\nB: Pause",








     NULL
};

// The game
typedef enum {MENU, DONE, SELECTING, MOVING, PAGING} game_state;
const byte WAIT_LEN = 3;

................................................................................
game_state state;		// Current game state
byte selected;	        	// substate indicator

const char *prompt;		// Menu prompt
#define PAUSED		"  Paused"
#define GAMEOVER 	"Game over!";
// The menu
enum {HELP, RESUME, NEW};
const char *const
menu[] = {" Help ",
          "Resume",
          " New  ",
          NULL};


/* Code to play the game. */
// Returns true if the shape is over clear tiles.
boolean
shape_clear(const shape *const s, const byte x, const byte y) {
     if (x + s->width > BOARD_SIZE || y + s->height > BOARD_SIZE)
          return 0;
................................................................................
          // Fall through to
     case RESUME:
          state = SELECTING;
          select_next();
          break;
     case HELP:
          state = PAGING;
          selected = 0;




          break;
     }
}

/* Code to draw things on the display */
// Coloring in things that aren't on the board.
void
................................................................................
     arduboy.print(msg);
}

void
draw_menu(void) {
     draw_msg(prompt);
     arduboy.print("\n\n\33 ");
     arduboy.print(menu[selected]);




     arduboy.print(" \32");
}

byte
draw_game(void) {
     byte can_place = 0;
     const shape *const s = &shapes[game.waiting[selected]];
................................................................................
     case MENU:
          draw_menu();
          break;
     case PAGING:
          arduboy.clear();
          draw_msg(help[selected], 0);
          if (selected) {
               arduboy.setCursor(0, 56);
               arduboy.write('\33');
          }
          arduboy.setCursor(62, 56);
          arduboy.write('\30');
          if (help[selected + 1] != NULL) {
               arduboy.setCursor(120, 56);
               arduboy.write('\32');
          }
          break;
     default:
          for (byte i = 0; i < WAIT_LEN; i += 1) {
               arduboy.setCursor(BLOCK_SIZE, (i + 3) * BLOCK_SIZE);
               arduboy.write(i == selected ? '+' : game.waiting[i] < 0 ? ' ' : '-');
................................................................................
const int store = 266;	// 10 (base 256) + 10. Because why not?
const int saved_game = store + 2;
const int flagbyte = 10;

void
setup(void) {
     arduboy.begin();
     arduboy.setTextWrap(true);

     if (EEPROM.read(store) != flagbyte || EEPROM.read(store + 1) != flagbyte) {
          // No saved game
          reset_game();
          game.high = 0;
          selected = HELP;
          EEPROM.put(saved_game, game);
................................................................................
     case MENU:
          if (arduboy.justPressed(A_BUTTON)) {
               do_menu();
          } else if (arduboy.justPressed(LEFT_BUTTON)) {
               if (selected)
                    selected -= 1;
               else
                    selected = sizeof(menu) / sizeof(char *) - 2;
          } else if (arduboy.justPressed(RIGHT_BUTTON)) {
               selected = (selected + 1) % (sizeof(menu) / sizeof(char *) - 1);
          }
          break;
     case PAGING:
          if (arduboy.justPressed(LEFT_BUTTON) && selected)
              selected -= 1;
          else if (arduboy.justPressed(RIGHT_BUTTON) & help[selected + 1] != NULL)
               selected += 1;







>

<
|
>
>
>
>
>
>
>
>







 







|
<
<
<
<
<
<







 







|
>
>
>
>







 







|
>
>
>
>







 







|


<
<

|







 







<







 







|

|







125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
159
160
161
162
163
164
165
166






167
168
169
170
171
172
173
...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
...
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
...
386
387
388
389
390
391
392
393
394
395


396
397
398
399
400
401
402
403
404
...
424
425
426
427
428
429
430

431
432
433
434
435
436
437
...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
     {2, 2, fours[3]},	// small 2x2 corners
     {2, 2, fours[4]},
     {2, 2, fours[5]},
     {2, 2, fours[6]},
};


/* Help screens - 8 lines of 20 characters on each screen */
const char *help[] = {

     "  Help Navigation\n\nPage back and forth\nwith \33 and \32 as\n"
     "indicated in the\nupper corners. Exit\nwith \30. Press \32 now.",
     "      Game play\n\nSelect shapes to\nplace on empty\nsquares on the 10x10\n"
     "game board. Filling a\nrow or column clears\nit.",
     "       Scoring\n\nPlacing a shape\nscores one point for\neach block in the\n"
     "shape, and ten points\nfor each line\ncleared.",
     "  Buttons: B pauses!\n Selecting\263  Moving\n\30 & \31     \263 Move with\n"
     "changes   \263 \33\31\30\32. \33\n\33 starts  \263 at left\nmoving.   \263 deselects\n"
     "A autofits\263 A places\nthen moves\263",
     NULL
};

// The game
typedef enum {MENU, DONE, SELECTING, MOVING, PAGING} game_state;
const byte WAIT_LEN = 3;

................................................................................
game_state state;		// Current game state
byte selected;	        	// substate indicator

const char *prompt;		// Menu prompt
#define PAUSED		"  Paused"
#define GAMEOVER 	"Game over!";
// The menu
enum {HELP, RESUME, NEW, KEYS, MENU_LAST};







/* Code to play the game. */
// Returns true if the shape is over clear tiles.
boolean
shape_clear(const shape *const s, const byte x, const byte y) {
     if (x + s->width > BOARD_SIZE || y + s->height > BOARD_SIZE)
          return 0;
................................................................................
          // Fall through to
     case RESUME:
          state = SELECTING;
          select_next();
          break;
     case HELP:
          state = PAGING;
          selected = HELP;
          break;
     case KEYS:
          state = PAGING;
          selected = KEYS;
          break;
     }
}

/* Code to draw things on the display */
// Coloring in things that aren't on the board.
void
................................................................................
     arduboy.print(msg);
}

void
draw_menu(void) {
     draw_msg(prompt);
     arduboy.print("\n\n\33 ");
     arduboy.print(selected == HELP ? " Help " :
                   selected == RESUME ? "Resume" :
                   selected == KEYS ? " Keys " :
                   selected == NEW ? "New" :
                   "BUG!");
     arduboy.print(" \32");
}

byte
draw_game(void) {
     byte can_place = 0;
     const shape *const s = &shapes[game.waiting[selected]];
................................................................................
     case MENU:
          draw_menu();
          break;
     case PAGING:
          arduboy.clear();
          draw_msg(help[selected], 0);
          if (selected) {
               arduboy.setCursor(0, 0);
               arduboy.write('\33');
          }


          if (help[selected + 1] != NULL) {
               arduboy.setCursor(120, 0);
               arduboy.write('\32');
          }
          break;
     default:
          for (byte i = 0; i < WAIT_LEN; i += 1) {
               arduboy.setCursor(BLOCK_SIZE, (i + 3) * BLOCK_SIZE);
               arduboy.write(i == selected ? '+' : game.waiting[i] < 0 ? ' ' : '-');
................................................................................
const int store = 266;	// 10 (base 256) + 10. Because why not?
const int saved_game = store + 2;
const int flagbyte = 10;

void
setup(void) {
     arduboy.begin();


     if (EEPROM.read(store) != flagbyte || EEPROM.read(store + 1) != flagbyte) {
          // No saved game
          reset_game();
          game.high = 0;
          selected = HELP;
          EEPROM.put(saved_game, game);
................................................................................
     case MENU:
          if (arduboy.justPressed(A_BUTTON)) {
               do_menu();
          } else if (arduboy.justPressed(LEFT_BUTTON)) {
               if (selected)
                    selected -= 1;
               else
                    selected = MENU_LAST - 1;
          } else if (arduboy.justPressed(RIGHT_BUTTON)) {
               selected = (selected + 1) % MENU_LAST;
          }
          break;
     case PAGING:
          if (arduboy.justPressed(LEFT_BUTTON) && selected)
              selected -= 1;
          else if (arduboy.justPressed(RIGHT_BUTTON) & help[selected + 1] != NULL)
               selected += 1;