Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

[WIP] Players can choose a name and they can replay a party #15

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

JulienMattiussi
Copy link
Collaborator

@JulienMattiussi JulienMattiussi commented Jun 8, 2018

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

src/game/game.py Outdated
ui = UIRender()

ui.clear_terminal()
Players.player1_name = ui.prompt_player_name(1, Players.player1_name)
Copy link
Contributor

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/party/game/

@@ -3,6 +3,20 @@
EMPTY_POSITION = '.'


class Players:
Copy link
Contributor

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.

Copy link
Collaborator Author

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)

Copy link
Contributor

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:
Copy link
Contributor

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

Copy link
Collaborator Author

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

Copy link
Contributor

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'
Copy link
Contributor

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):
Copy link
Contributor

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

Copy link
Collaborator Author

@JulienMattiussi JulienMattiussi Jun 8, 2018

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)
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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

Copy link
Contributor

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):
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants