-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user to undo single step #17
Conversation
This commit adds fPreviousBoard, which saves the board state before making a move, to allow for undoing a move via calling Game::undoMove()
User can undo by pressing 'u' on the terminal
The new name is more appropriate as H2048_BOARD_CHANGED covers both move made and undos.
How it works: * canUndo is included with every H2048_BOARD_CHANGED messages * GameBoard::boardChanged is modified to include the canUndo passed from the H2048_BOARD_CHANGED messages * The GUI can now know whether to enable/disable the undo button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the "u" key for "Undo" in the WindowBoard, too?
(Not sure how the commandline version is supposed to work.)
Game.cpp
Outdated
@@ -8,6 +8,7 @@ | |||
|
|||
#include <algorithm> | |||
#include <cstdlib> | |||
#include <cstring> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I intended to use std::memcpy to copy the tables, but then I switched to a for-loop and I forgot to remove that header. My mistakes.
WindowBoard.cpp
Outdated
fSending = true; | ||
} | ||
|
||
void | ||
WindowBoard::gameEnded() | ||
{ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray tab
Instead of adding an undo button, I would add it as an option on a menu of the menubar. If you put an undo button in front of the user, they are more likely to use it more often to cheat. But I'll let @humdingerb make that call. |
How about making that another GCI task? |
I've added a 'u' key for undo in the command-line version, not the GUI though. I'll work on it tomorrow since it's already midnight in my place. |
Can you add the shortcut to the GUI, too? |
I've added it in 2042969. |
Works, thanks! |
Undoing a step doesn't decrease the score accordingly. Sorry I didn't notice sooner... |
Hmm that's weird, it works on my side (at least on my branch). I can't test master because it doesn't compile currently (#18, last comment) |
You right. It does work... Probably didn't relize those were "non-scoring" moves that - of course - don't change the score when reverted. Sorry... :) |
No problem :) |
This pull request adds a button to allow user to undo a single step.
The button is initially disabled after a new game. After a move is made the button is enabled, and after user undoes a move, the button is disabled again. User can undo even after encountered a Game Over.
This pull request implements #9.