-
Notifications
You must be signed in to change notification settings - Fork 2
[WIP] Players can choose a name and they can replay a party #15
base: master
Are you sure you want to change the base?
Conversation
src/game/game.py
Outdated
ui = UIRender() | ||
|
||
ui.clear_terminal() | ||
Players.player1_name = ui.prompt_player_name(1, Players.player1_name) |
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 mutating static class attributes on the fly ? :o
src/game/ui.py
Outdated
|
||
def prompt_restart(self): | ||
try: | ||
return input("Let's play another party ? (o/n) ") == 'o' |
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.
s/party/game/
src/game/tools.py
Outdated
@@ -3,6 +3,20 @@ | |||
EMPTY_POSITION = '.' | |||
|
|||
|
|||
class Players: |
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.
It's very strange to have a "Players" class in "tools.py". Moreover, it seems that you use Players class as a property container, i'm not sure that it's the best way to achieve this.
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.
It was also destined to store players scores (other story)
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.
In general, all this informations are stored in only one object (a "game" state) to ensure data integrity and synchronicity.
src/game/ui.py
Outdated
def prompt_player_name(self, player_id, default_name): | ||
try: | ||
name = input("Player " + str(player_id) + ", what is your name (" + default_name + " if empty) ? ") | ||
if len(name) > 0: |
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.
It's still possible to add an empty name with space
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.
That's right. I don't see some real reason to forbid "spaces names" if the player has entered it, but I 'll manage for the game visibility
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.
It's a bonus ;)
src/game/ui.py
Outdated
|
||
def prompt_restart(self): | ||
try: | ||
return input("Let's play again ? (o/n) ") == 'o' |
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.
y/n
def players_to_string(self, game_turn): | ||
player_1 = self.selected_player_to_string('Player 1', game_turn.player_one_active) | ||
player_2 = self.selected_player_to_string('Player 2', not game_turn.player_one_active) | ||
def players_to_string(self, game_turn, players): |
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.
In the case you've create a "Player" class, it would be possible to implement a "special" method (str) to achieve this task (cast an object to a string representation). This is the Java equivalent of toString().
More informations here: https://openclassrooms.com/courses/apprenez-a-programmer-en-python/les-methodes-speciales-1
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.
I thinked about it, but I prefer to keep all render methods in the UI class
In this case : Changing UI doesn't impact other games classes
@@ -22,24 +22,41 @@ def prompt_piece_selection(self, game_state): | |||
game_state.message = "You must choose a number available in the list" | |||
except ValueError: | |||
game_state.message = "You have to type number between 1 and " + str(PIECES_NUMBER) | |||
self.display_game(game_state) | |||
self.display_game(game_state, players) |
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.
It's strange to not integrate the players into the game_state, why have you choice this architecture ?
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.
State represent the state of the current round game.
Players remains between rounds
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.
You can still integrate player into the game state even if they don't change. This way, you manipulate one state only and it's easier to reason about and test
@@ -66,13 +67,13 @@ def check_position_availability(self, x, y): | |||
def switch_player(self): | |||
self.game_turn.player_one_active = not self.game_turn.player_one_active | |||
|
|||
def check_winner(self): | |||
def check_winner(self, players): |
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.
"check_winner" is not a good name for this function. Moreover, 1 function = 1 task. Here, the function is responsible of "message" change and return a boolean
I would create a function to get the current winner (or nul if no one) and another to assign the message from the returned value instead.
https://trello.com/c/BsVVCYmg
https://trello.com/c/TbJAqfdC
https://trello.com/c/33ocNyd9
Name is asked at start
Replay is asked at end of party
Score is displayed
Writing tests in progress