def __init__(self, master: Frame, player: Player, pos: int, bg="light grey"): self.pos = pos self.player_frame = Frame(master, bd=1, relief=SUNKEN, bg=bg) self.player_frame.columnconfigure(0, weight=1) self.player_frame.rowconfigure(0, weight=1) self.player_frame.rowconfigure(1, weight=1) self.player_frame.rowconfigure(2, weight=1) images = Images() self.label = Label(self.player_frame, text=player.get_name(), font=Font(size=30), bg=bg) self.label.grid(row=0, sticky="nsew") self.controlPanel = Frame(self.player_frame, bg=bg) self.controlPanel.rowconfigure(0, weight=1) self.controlPanel.rowconfigure(1, weight=1) self.controlPanel.rowconfigure(2, weight=1) self.controlPanel.columnconfigure(0, weight=1) self.controlPanel.columnconfigure(1, weight=1) self.btn1 = Button(self.controlPanel, image=images.plus) self.btn1.image = images.plus self.btn1.grid(row=0, column=pos, padx=5, pady=5, sticky=S + N + E + W) self.entry = Entry(self.controlPanel, font=Font(size=30), justify="center", width=3) self.entry.grid(row=1, column=pos, padx=5, pady=5, sticky=S + N + E + W) self.btn2 = Button(self.controlPanel, image=images.minus) self.btn2.image = images.minus self.btn2.grid(row=2, column=pos, padx=5, pady=5, sticky=S + N + E + W) self.labelLife = Label(self.controlPanel, text=str(player.get_life()), font="Helvetica 50 bold", bg=bg) self.labelLife.grid(row=0, column=1 - pos, rowspan=3, sticky=S + N + E + W) self.controlPanel.grid(row=1, sticky=S + N + E + W) self.buddy_call_button = Button(self.player_frame, text="Buddy Call", font=Font(size=20)) self.buddy_call_button.grid(row=2, sticky="nsew")
def choice_import_tournament(self, tournaments_db): View.intro_choice_import_tournament() result = self.ask_which_tournament()[0] players = Players() tournament = Tournament(result["name"], result["location"], players, result["rounds"], result["timer"], result["description"]) tournament.id = result["id"] for player in result["players"]["list"]: current_player = Player(player["name"], player["first_name"], player["gender"], player["birthday"], player["rank"]) current_player.score = player["score"] players.add(current_player) for rounds in result["round_list"]: temp_round = Matches() for matches in rounds["list"]: white_player = Player(matches["white_player"]["name"], matches["white_player"]["first_name"], matches["white_player"]["gender"], matches["white_player"]["birthday"], matches["white_player"]["rank"]) white_player.score = matches["white_player"]["score"] black_player = Player(matches["black_player"]["name"], matches["black_player"]["first_name"], matches["black_player"]["gender"], matches["black_player"]["birthday"], matches["black_player"]["rank"]) white_player.score = matches["black_player"]["score"] temp_match = Match(white_player, black_player) if matches["winner"] is not None: temp_match.set_winner( Player(matches["winner"]["name"], matches["winner"]["first_name"], matches["winner"]["gender"], matches["winner"]["birthday"], matches["winner"]["rank"])) temp_match.winner.score = matches["winner"]["score"] temp_round.add_match(temp_match) tournament.add_round(temp_round) View.intro_list_of_players() for (i, player) in enumerate(players.list): View.display_player_firstname_lastname(str(i), player.name, player.first_name) Controller.play_rounds(self, tournament, players) View.display_results(tournament)
def create_tournament(self): View.intro_choice_create_tournament() for (i, player) in enumerate(self.players_db): View.display_player_firstname_lastname(str(i), player["name"], player["first_name"]) id_list = [] for i in range(8): id_list.append(View.add_player(id_list, len(self.players_db))) players = Players() for (i, element) in enumerate(id_list): data = self.players_db.get(doc_id=element + 1) players.add( Player(data["name"], data["first_name"], data["gender"], data["birthday"], data["rank"])) View.intro_list_of_players() for (i, player) in enumerate(players.list): View.display_player_firstname_lastname(str(i), player.name, player.first_name) player.reset_score() tournament = self.init_tournament(players) self.tournaments_db.insert(tournament.to_dict()) View.intro_list_of_players() Controller.play_rounds(self, tournament, players) View.display_results(tournament)
def create_player(self): name = self.view.get_name() first_name = self.view.get_first_name() birthday = self.view.get_birth_date() gender = self.view.get_gender() rank = self.view.get_ranking() return Player(name, first_name, birthday, gender, rank)
class TestPlayer(unittest.TestCase): """ UnitTest class to test functionality of the Player class and its functions such as add_my_ship and add_opp_ship. @author sahil1105 """ def setUp(self): """ Set up the test suite by initializing an instant of the Player class. :return: None """ self.player = Player('Sahil', (5, 5)) def test_add_my_ship(self): """ Test the functionality of the add_my_ship function. :return: None """ assert self.player.add_my_ship(Ship((0, 1), 3, (1, 0))) is True # Valid add assert self.player.my_ships_counter[ 3] == 1 # Check that the counter was incremented assert self.player.add_my_ship(Ship((5, 0), 6, (-1, 0))) is False # Invalid add assert 6 not in self.player.my_ships_counter # Ensure counter was not incremented assert self.player.add_my_ship(Ship((0, 4), 3, (1, 0))) is True # Valid add assert self.player.my_ships_counter[ 3] == 2 # Check that the counter was incremented def test_add_opp_ship(self): """ Test the functionality of the add_opp_ship function. :return: None. """ self.player.add_opp_ship(3) # Valid add assert self.player.opp_ships_counter[ 3] == 1 # Check that the counter was incremented self.player.add_opp_ship(3) # Valid add assert self.player.opp_ships_counter[ 3] == 2 # Check that the counter was incremented
def __init__(self, root): self.__player = Player.Player() self.__root = root self.__settings = Settings.Settings() self.__menuArea = tk.Frame(root, width=root.winfo_screenwidth()) self.__menuArea.pack(anchor=NW) background = tk.Frame(root, width=root.winfo_screenwidth(), height=root.winfo_screenheight(), background=self.BACKGROUND_COLOR) background.pack(fill=BOTH, expand=True, pady=5, padx=5) self.__viewArea = tk.Frame(background, background=self.BACKGROUND_COLOR) self.__viewArea.pack(pady=10, padx=10, fill=BOTH, expand=True) self.__menuController = MenuController.MenuController( self.__viewArea, self) self.__gameController = GameController.GameController( self.__viewArea, self.__player, self) self.__menuController.DisplayBasicMenu(self.__menuArea) root.bind('<Escape>', lambda e, root=self.__viewArea: self.OpenMenu(root)) root.bind('<x>', lambda e: self.CloseApplication()) self.__sounds = Sound() self.__mixer = pygame.mixer self.__mixer.init() self.OpenMenu()
class TestIsLegalMoveCastling: white_player = Player(1) black_player = Player(0) board_one = Board() board_one.pieces_into_specified_positions({ "a1": Rook(None, white_player), "b1": Knight(None, white_player), "c1": Bishop(None, white_player), "d1": Queen(None, white_player), "e1": King(None, white_player), "c4": Bishop(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d2": Pawn(None, white_player), "e4": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b7": Pawn(None, black_player), "c7": Pawn(None, black_player), "d6": Pawn(None, black_player), "e5": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "g4": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_two = Board() board_two.pieces_into_specified_positions({ "a1": Rook(None, white_player), "b1": Knight(None, white_player), "c1": Bishop(None, white_player), "d1": Queen(None, white_player), "e1": King(None, white_player, True), "c4": Bishop(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d2": Pawn(None, white_player), "e4": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b7": Pawn(None, black_player), "c7": Pawn(None, black_player), "d6": Pawn(None, black_player), "e5": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "g4": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_three = Board() board_three.pieces_into_specified_positions({ "a1": Rook(None, white_player), "b1": Knight(None, white_player), "c1": Bishop(None, white_player), "d1": Queen(None, white_player), "e1": King(None, white_player), "c4": Bishop(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player, True), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d2": Pawn(None, white_player), "e4": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b7": Pawn(None, black_player), "c7": Pawn(None, black_player), "d6": Pawn(None, black_player), "e5": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "g4": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_four = Board() board_four.pieces_into_specified_positions({ "a1": Rook(None, white_player), "b1": Knight(None, white_player), "c1": Bishop(None, white_player), "d1": Queen(None, white_player), "e1": King(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d2": Pawn(None, white_player), "e4": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b6": Pawn(None, black_player), "c7": Pawn(None, black_player), "d7": Pawn(None, black_player), "e5": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "a6": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_five = Board() board_five.pieces_into_specified_positions({ "a1": Rook(None, white_player), "b1": Knight(None, white_player), "c1": Bishop(None, white_player), "d1": Queen(None, white_player), "e1": King(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d2": Pawn(None, white_player), "e4": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b6": Pawn(None, black_player), "c7": Pawn(None, black_player), "d7": Pawn(None, black_player), "e5": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "f1": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_six = Board() board_six.pieces_into_specified_positions({ "a1": Rook(None, white_player), "b1": Knight(None, white_player), "c1": Bishop(None, white_player), "d1": Queen(None, white_player), "e1": King(None, white_player), "f1": Bishop(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d2": Pawn(None, white_player), "e2": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b7": Pawn(None, black_player), "c7": Pawn(None, black_player), "d7": Pawn(None, black_player), "e7": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "c8": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_seven = Board() board_seven.pieces_into_specified_positions({ "a1": Rook(None, white_player), "a3": Knight(None, white_player), "e3": Bishop(None, white_player), "d3": Queen(None, white_player), "e1": King(None, white_player), "f1": Bishop(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "c2": Pawn(None, white_player), "d4": Pawn(None, white_player), "e2": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b7": Pawn(None, black_player), "c6": Pawn(None, black_player), "d5": Pawn(None, black_player), "e6": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "c8": Bishop(None, black_player), "a5": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) board_eight = Board() board_eight.pieces_into_specified_positions({ "a1": Rook(None, white_player), "e3": Bishop(None, white_player), "d2": Queen(None, white_player), "e1": King(None, white_player), "f1": Bishop(None, white_player), "f3": Knight(None, white_player), "h1": Rook(None, white_player), "a2": Pawn(None, white_player), "b2": Pawn(None, white_player), "d4": Pawn(None, white_player), "e2": Pawn(None, white_player), "f2": Pawn(None, white_player), "g2": Pawn(None, white_player), "h2": Pawn(None, white_player), "a7": Pawn(None, black_player), "b7": Pawn(None, black_player), "c7": Pawn(None, black_player), "d6": Pawn(None, black_player), "e7": Pawn(None, black_player), "f7": Pawn(None, black_player), "g7": Pawn(None, black_player), "h7": Pawn(None, black_player), "a8": Rook(None, black_player), "b8": Knight(None, black_player), "b1": Bishop(None, black_player), "d8": Queen(None, black_player), "e8": King(None, black_player), "f8": Bishop(None, black_player), "g8": Knight(None, black_player), "h8": Rook(None, black_player), }) turn_one = Turn(starting_board=board_one, player=white_player, starting_square=board_one.dict_of_64_squares["e1"], ending_square=board_one.dict_of_64_squares["g1"]) turn_two = Turn(starting_board=board_one, player=white_player, starting_square=board_one.dict_of_64_squares["h1"], ending_square=board_one.dict_of_64_squares["f1"]) turn_three = Turn(starting_board=board_one, player=white_player, starting_square=board_one.dict_of_64_squares["e1"], ending_square=board_one.dict_of_64_squares["f1"]) turn_four = Turn(starting_board=board_one, player=white_player, starting_square=board_one.dict_of_64_squares["e1"], ending_square=board_one.dict_of_64_squares["e2"]) turn_five = Turn(starting_board=board_two, player=white_player, starting_square=board_two.dict_of_64_squares["e1"], ending_square=board_two.dict_of_64_squares["g1"]) turn_six = Turn(starting_board=board_three, player=white_player, starting_square=board_three.dict_of_64_squares["e1"], ending_square=board_three.dict_of_64_squares["g1"]) turn_seven = Turn(starting_board=board_four, player=white_player, starting_square=board_four.dict_of_64_squares["e1"], ending_square=board_four.dict_of_64_squares["g1"]) turn_eight = Turn(starting_board=board_five, player=white_player, starting_square=board_five.dict_of_64_squares["e1"], ending_square=board_five.dict_of_64_squares["g1"]) turn_nine = Turn(starting_board=board_six, player=white_player, starting_square=board_six.dict_of_64_squares["e1"], ending_square=board_six.dict_of_64_squares["g1"]) turn_ten = Turn(starting_board=board_seven, player=white_player, starting_square=board_seven.dict_of_64_squares["e1"], ending_square=board_seven.dict_of_64_squares["g1"]) turn_eleven = Turn(starting_board=board_eight, player=white_player, starting_square=board_eight.dict_of_64_squares["e1"], ending_square=board_eight.dict_of_64_squares["g1"]) @pytest.mark.parametrize( "test_input, expected", [ (turn_one, True), # No complications (turn_two, False), # Rook selected to move instead of King (turn_three, False), # King moved one space over instead of two (turn_four, False), # King moved to different row (turn_five, False), # King was moved in a previous turn (turn_six, False), # Rook was moved in a previous turn (turn_seven, False), # King passes through check while castling (turn_eight, False), # King's path is blocked by enemy piece (turn_nine, False), # King's path is blocked by own piece (turn_ten, False), # King starts off in check (turn_eleven, False), # Rook's path is blocked by enemy piece ]) def test_works_for_expected_input(self, test_input, expected): # Returns expected value when passed valid input. result = test_input.is_legal_move_castling() assert result == expected, "Expected Turn to identify legal castling move."
def __init__(self, life: int = 10): self.__init_life = life self.__players = [Player("Player 1", life), Player("Player 2", life)]
def setUp(self): """ Set up the test suite by initializing an instant of the Player class. :return: None """ self.player = Player('Sahil', (5, 5))
def __init__(self): self.UI = MainUI() self.UI.moveButton_1.clicked.connect(self.event_moveButton1) self.UI.moveButton_2.clicked.connect(self.event_moveButton2) self.UI.moveButton_3.clicked.connect(self.event_moveButton3) self.UI.moveButton_4.clicked.connect(self.event_moveButton4) self.UI.actionButton_1.clicked.connect(self.event_actionButton1) self.UI.actionButton_2.clicked.connect(self.event_actionButton2) self.UI.actionButton_3.clicked.connect(self.event_actionButton3) self.UI.actionButton_4.clicked.connect(self.event_actionButton4) self.player = Player() self.player.place="메인 화면" self.v1 = Village() self.v1.name="숲속 피난민촌" self.v1.linked_vil=["도심속 지하벙커도시", "군사기지"] self.v1.linked_dun=["형광색 늪지대","쓰레기강","역동적인 숲"] self.v1.npc = ["외팔이 아저씨", "땡중 삼장", "송이장"] self.v2 = Village() self.v2.name="도심속 지하벙커도시" self.v2.linked_vil = ["숲속 피난민촌", "군사기지"] self.v2.linked_dun = ["악마들의 교회", "음침한 병원", "폐쇄된 대형마트"] self.v2.npc = ["한목사", "병원앞의 꼬마", "마트앞 시위대"] self.v3 = Village() self.v3.name="군사기지" self.v3.linked_vil = ["숲속 피난민촌", "도심속 지하벙커도시"] self.v3.linked_dun = ["대형 군용막사", "사령관실", "군병원"] self.v3.npc = ["탈영병", "삐까뻔쩍한 건물앞 보초", "생체실험 총책임자"] # 이름, hp, dmg, gold self.d11 = Dungeon() self.d11.map = MapData.maps[0] self.d11.monster = [["겁나 큰개구리", 100, 10, 10], ["머리 셋달린 악어", 105, 12, 10], ["식인 부레옥잠", 110, 13, 10], ["팔뚝만한 실지렁이", 100, 14, 10]] self.d11.boss = ["겁나 큰개구리와 합체한 머리 셋달린 악어", 130, 16, 10] self.d11.initX = 3 self.d11.initY = 3 self.d12 = Dungeon() self.d12.map = MapData.maps[1] self.d12.monster = [["겁나 큰입 베스", 120, 15, 10], ["걸어다니는 독버들", 130, 16, 10], ["입이 배까지 찢어지는 뉴트리아", 140, 17, 10], ["붉은 귀 거북", 150, 18, 10]] self.d12.boss = ["쓰레기강 요괴 사오정", 180, 22, 10] self.d12.initX = 3 self.d12.initY = 3 self.d13 = Dungeon() self.d13.map = MapData.maps[2] self.d13.monster = [["거짓말하는 자작나무", 160, 20, 10], ["야무진 오동나무", 175, 22, 10], ["핏빛의 단풍나무", 180, 23, 10], ["유연한 소나무", 185, 24, 10]] self.d13.boss = ["오동나무 아저씨", 200, 25, 10] self.d13.initX = 3 self.d13.initY = 3 self.d21 = Dungeon() self.d21.map = MapData.maps[3] self.d21.monster = [["미쳐버린 광신도", 190, 25, 10], ["추격자 집사", 195, 26, 10], ["끈질긴 전도사", 200, 27, 10], ["현혹하는 목사", 205, 28, 10]] self.d21.boss = ["악마와 계약한 장로", 220, 32, 10] self.d21.initX = 4 self.d21.initY = 3 self.d22 = Dungeon() self.d22.map = MapData.maps[4] self.d22.monster = [["핵폐기물 좀비", 225, 29, 10], ["사일런트힐 너스", 220, 30, 10], ["피곤한 레지던트", 215, 32, 10], ["어리버리한 인턴", 210, 33, 10]] self.d22.boss = ["문도박사", 240, 35, 10] self.d22.initX = 3 self.d22.initY = 1 self.d23 = Dungeon() self.d23.map = MapData.maps[5] self.d23.monster = [["오염된 시식코너 판매원", 230, 35, 10], ["쌍칼 정육점직원", 240, 36, 10], ["돈많은 진상손님", 245, 37, 10], ["돌진하는 카트", 235, 39, 10]] self.d23.boss = ["사장아들 매니저", 255, 42, 10] self.d23.initX = 6 self.d23.initY = 1 self.d31 = Dungeon() self.d31.map = MapData.maps[6] self.d31.monster = [["고문관 이등병", 250, 40, 10], ["일개미 일병", 255, 41, 10], ["맞고자란 상병", 260, 42, 10], ["꼬장킹 병장", 265, 44, 10]] self.d31.boss = ["전역짤린 병장", 275, 48, 10] self.d31.initX = 4 self.d31.initY = 3 self.d32 = Dungeon() self.d32.map = MapData.maps[7] self.d32.monster = [['대대장', 270, 45, 10], ['연대장', 275, 47, 10], ['사단장', 280, 49, 10], ['군단장', 290, 52, 10]] self.d32.boss = ["사령관", 300, 54, 10] self.d32.initX = 1 self.d32.initY = 1 self.d33 = Dungeon() self.d33.map = MapData.maps[8] self.d33.monster = [['군의관', 250, 40, 10], ['간호장교', 265, 44, 10], ['꾀병걸린 병장', 260, 42, 10], ['실패한 실험체', 270, 30, 10]] self.d33.boss = ["생체병기-73", 320, 58, 10] self.d33.initX = 1 self.d33.initY = 1 self.dunList = ["형광색 늪지대","쓰레기강","역동적인 숲","악마들의 교회", "음침한 병원", "폐쇄된 대형마트","대형 군용막사", "사령관실", "군병원"] self.dun = Dungeon() #현재 던전 self.mon = Monster() #현재 몬스터