-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat/tictactoelocalmult #125
Conversation
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.
The code also should be formatted as they asked for.
class MultiplayerTicTacToe(val view:TicTacToeFragment,player:MOVES) : TicTacToeGame(player){ | ||
override fun putChoice(square: Int) { | ||
if(!gameRunning) | ||
return | ||
val cell = square % 3 | ||
val row = (square / 3) | ||
if(matrix[row][cell] != MOVES.EMPTY) | ||
return | ||
matrix[row][cell] = player | ||
view.updateUI(square, player) | ||
calculate() | ||
player = if(player == MOVES.CROSS) MOVES.CIRCLE else MOVES.CROSS | ||
} | ||
override fun gameOver(winner:MOVES){ | ||
gameRunning = false | ||
view.gameOver(winner) | ||
} | ||
} |
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.
Are you sure this is the best approach ? I would prefer not change UI in the logic here, but instead only update the current state, and then ui listens for changes and updates the UI.
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.
Sure that would be an approach too! I choose this one because in your approach I needed to have an observer for the TTT state which is a bit more problematic to implement correctly while with a callback based approach it was super straightforward and easy to implement.
Sure thank you for reminding me! |
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.
great job, well-abstracted code
This branch optimises current TTT implementation to follow android best practices in fragment managing and Navigation Paths. The interface of TTT has been slightly changed to allow better interoperability between different subclasses of TicTacToeGame. The following PR also adds support for local multiplayer.