diff --git a/a2sudoku/game.c b/a2sudoku/game.c index c23ef58..7138507 100644 --- a/a2sudoku/game.c +++ b/a2sudoku/game.c @@ -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; diff --git a/a2sudoku/game.h b/a2sudoku/game.h index 3976400..b07133e 100644 --- a/a2sudoku/game.h +++ b/a2sudoku/game.h @@ -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); diff --git a/a2sudoku/ui.c b/a2sudoku/ui.c index dbed015..1509a71 100644 --- a/a2sudoku/ui.c +++ b/a2sudoku/ui.c @@ -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':