2022-04-04 06:16:33 +00:00
|
|
|
from Player import *
|
|
|
|
from Board import *
|
2022-04-14 20:48:16 +00:00
|
|
|
from GameView import *
|
2022-04-04 06:16:33 +00:00
|
|
|
|
|
|
|
class GameController(object):
|
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
""":version:
|
2022-04-04 06:16:33 +00:00
|
|
|
:author:
|
2022-04-19 07:49:45 +00:00
|
|
|
|
|
|
|
|
2022-04-04 06:16:33 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
""" ATTRIBUTES
|
|
|
|
|
|
|
|
list_of_players (private)
|
|
|
|
|
|
|
|
board (private)
|
|
|
|
|
2022-04-14 20:48:16 +00:00
|
|
|
game_view (private)
|
|
|
|
|
2022-04-04 06:16:33 +00:00
|
|
|
"""
|
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
COLORS=["black", "yellow", "green", "red", "blue", "purple"]
|
2022-04-04 06:16:33 +00:00
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
def __init__(self, number_of_players:int=4):
|
|
|
|
self.list_of_players = list()
|
|
|
|
for i in range(number_of_players):
|
|
|
|
self.add_player("Player " + str(i), GameController.COLORS[i])
|
2022-04-19 08:15:33 +00:00
|
|
|
print([[p.name, p.color] for p in self.list_of_players])
|
2022-04-19 07:49:45 +00:00
|
|
|
self.board = Board(GameController.COLORS, number_of_players)
|
2022-04-19 08:15:33 +00:00
|
|
|
for p in self.list_of_players:
|
|
|
|
p.init_house(self.board)
|
2022-04-19 07:49:45 +00:00
|
|
|
self.game_view = GameView()
|
2022-04-04 06:16:33 +00:00
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
def add_player(self, name, color):
|
|
|
|
"""Add a player to the game
|
|
|
|
|
|
|
|
:param name: Name of the player
|
|
|
|
:param color: Color of the player
|
|
|
|
:returns: Player : p
|
2022-04-04 06:16:33 +00:00
|
|
|
|
|
|
|
"""
|
2022-04-19 07:49:45 +00:00
|
|
|
p = Player(name, color)
|
|
|
|
self.list_of_players.append(p)
|
|
|
|
return p
|
2022-04-04 06:16:33 +00:00
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
def remove_player(self, color):
|
|
|
|
""" Remove player from game
|
2022-04-04 06:16:33 +00:00
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
:param color: Color of the player to be removed
|
|
|
|
:returns: True
|
2022-04-04 06:16:33 +00:00
|
|
|
|
2022-04-19 07:49:45 +00:00
|
|
|
"""
|
|
|
|
found = False
|
|
|
|
for p in self.list_of_players:
|
|
|
|
if p.color == color:
|
|
|
|
self.list_of_players.remove(p)
|
|
|
|
found = True
|
|
|
|
print("Player with color {} removed".format(color))
|
|
|
|
else:
|
|
|
|
pass # still not found
|
|
|
|
if found == False:
|
|
|
|
print("No player with color {} available for extractin.".format(color))
|
|
|
|
|
|
|
|
return True
|