Add a way to restart your puzzle from the beginning.

This commit is contained in:
Jeremy Rand 2015-07-16 20:00:45 -05:00
parent 45ca073efa
commit 066e8af297
3 changed files with 36 additions and 2 deletions

View File

@ -66,6 +66,32 @@ void refreshPos(tPos x, tPos y)
}
void restartGame(void)
{
tPos x, y;
tGameSquare *square;
for (y = 0; y < BOARD_SIZE; y++) {
for (x = 0; x < BOARD_SIZE; x++) {
square = &(SQUARE_XY(x, y));
if (square->knownAtStart)
continue;
if ((square->value == EMPTY_SQUARE) &&
(square->scratchValues == 0))
continue;
square->value = EMPTY_SQUARE;
square->scratchValues = 0;
square->correct = false;
square->invalid = false;
refreshPos(x, y);
}
}
}
void startGame(tDifficulty difficulty, tUpdatePosCallback callback)
{
tPos x, y;

View File

@ -43,6 +43,8 @@ extern bool toggleScratchValueAtPos(tPos x, tPos y, tSquareVal val);
// Returns false if the last move cannot be undone.
extern bool undoLastMove(void);
extern void restartGame(void);
extern void saveGame(void);
extern bool loadGame(tUpdatePosCallback callback);

View File

@ -282,14 +282,14 @@ void displayInstructions(void)
"toggle a scratch value. Press 0 to\n"
"clear a square. Play ends when the\n"
"puzzle is solved.\n"
"\n"
" Difficulty : %s\n"
" Show invalid values : %s\n"
" Show wrong values : %s\n"
"\n"
"Press escape or Q to quit at any time.\n"
"Press O to change options.\n"
"Press R to start a new game.\n"
"Press R to restart the current game.\n"
"Press N to start a new game.\n"
"Press H to see this info again.\n"
"Press U to undo your last move.\n"
" Press O to change options now or any\n"
@ -597,6 +597,12 @@ bool playGame(void)
case 'r':
case 'R':
shouldSave = false;
restartGame();
break;
case 'n':
case 'N':
return true;
case 'q':