Skip to content
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

Merged
merged 7 commits into from
May 20, 2022
Merged

Feat/tictactoelocalmult #125

merged 7 commits into from
May 20, 2022

Conversation

leonardopennino
Copy link
Collaborator

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.

Copy link
Collaborator

@gaetschwartz gaetschwartz left a 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.

Comment on lines 6 to 23
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)
}
}
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@leonardopennino
Copy link
Collaborator Author

The code also should be formatted as they asked for.

Sure thank you for reminding me!

Copy link
Collaborator

@adam-narozniak adam-narozniak left a 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

@leonardopennino leonardopennino merged commit 5dba849 into main May 20, 2022
@leonardopennino leonardopennino deleted the feat/tictactoelocalmult branch May 20, 2022 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actual: 7h estimated: 7h Issues estimated to take 7h of work. Waiting for review This PR is waiting for review.
Projects
None yet
3 participants