From ba5b38e7c419f35492b2fb4b90eec10659e072f7 Mon Sep 17 00:00:00 2001 From: Martin Putzlocher Date: Tue, 19 Apr 2022 10:15:33 +0200 Subject: [PATCH] =?UTF-8?q?Initialisierung=20von=20Board=20und=20H=C3=A4us?= =?UTF-8?q?ern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maedn/Board.py | 23 ++++++++++++++++------- maedn/Field.py | 29 +++++++++++++++-------------- maedn/GameController.py | 3 +++ maedn/Player.py | 5 ++++- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/maedn/Board.py b/maedn/Board.py index 823e86e..59b92a1 100644 --- a/maedn/Board.py +++ b/maedn/Board.py @@ -38,11 +38,10 @@ class Board(object): for i in range(10): f = Field.Field(self, i, self.colors[n], house=False) self._list_all_fields.append(f) + IDlist = [f.get_id() for f in self._list_all_fields] print(IDlist) - - def get_next_standard_field(self, current_field): """ @@ -52,9 +51,11 @@ class Board(object): @author """ - pass + current_index = self._list_all_fields.index(current_field) + next_field = self._list_all_fields[current_index + 1] + return next_field - def get_next_field_by_color(self, current_field, color = "black"): + def get_next_field_by_color(self, current_field, color_of_stone = "black"): """ :param Field: current_field : Current field @@ -65,8 +66,16 @@ class Board(object): @author """ - curr_id = current_field.get_id() - - + current_field_color = current_field.get_color() + next_field = self.get_next_standard_field(current_field) + next_field_color = next_field.get_color() + + if color_of_stone == next_field_color and current_field_color != next_field_color: + # TODO + # next_field = im Haus des aktuellen Spielers + pass + else: + pass + return next_field diff --git a/maedn/Field.py b/maedn/Field.py index 63b5a48..cf0cfe5 100644 --- a/maedn/Field.py +++ b/maedn/Field.py @@ -7,21 +7,11 @@ class Field(): :author: Martin Putzlocher - """ - - """ ATTRIBUTES - - board (private) - - occupied (private) - - number (private) - - color (private) - """ def __init__(self, board:Board.Board=None, number:int=0, color:str="black", house:bool=False): + """ Constructor + """ if board is None: raise Exception("No Board Exception") self.board = board @@ -30,6 +20,7 @@ class Field(): self._h = house self._id = "" self.set_id(color, number, house) + self.occupied = False def get_id(self): """ Get ID of field instance @@ -52,8 +43,18 @@ class Field(): self._id = "S" + color[:3] + str(number) return self._id - def get_next_field(self, color_of_stone = "black"): - """Give back next field on board, dependent on the color of a stone on the current + def get_number(self): + """ Get the number 0...9 of the field + """ + return self._n + + def get_color(self): + """ Get the color of the field + """ + return self._c + + def get_next_field(self, color_of_stone="black"): + """ Give back next field on board, dependent on the color of a stone on the current field. :param color_of_stone: Default value = "black") diff --git a/maedn/GameController.py b/maedn/GameController.py index 6e0bce7..a6bef61 100644 --- a/maedn/GameController.py +++ b/maedn/GameController.py @@ -26,7 +26,10 @@ class GameController(object): self.list_of_players = list() for i in range(number_of_players): self.add_player("Player " + str(i), GameController.COLORS[i]) + print([[p.name, p.color] for p in self.list_of_players]) self.board = Board(GameController.COLORS, number_of_players) + for p in self.list_of_players: + p.init_house(self.board) self.game_view = GameView() def add_player(self, name, color): diff --git a/maedn/Player.py b/maedn/Player.py index bf69fbf..d666c75 100644 --- a/maedn/Player.py +++ b/maedn/Player.py @@ -22,9 +22,12 @@ class Player(): def __init__(self, name:str="Nobody", color:str="black"): self.name = name self.color = color - self.house = House() + self.house = None self.set_of_stones = list() + def init_house(self, board): + self.house = House(board, self.color) + def take_turn(self): """