Skip to content

Commit

Permalink
feat(UI-UX): display winner name for local multiplayer [TTTK-89]
Browse files Browse the repository at this point in the history
  • Loading branch information
HOOK-Hawkins committed Mar 18, 2024
1 parent 61760dc commit 130ac46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 8 additions & 5 deletions UI/endscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
#from .field_frame import Field

class EndScreen(base_frame):
def __init__(self, master, win:bool, winner, final_playfield, *args, **kwargs):
def __init__(self, master, win:bool, winner, final_playfield, *args, local_mp=False, **kwargs):
super().__init__(master)
self._create_widgets(win, winner, final_playfield)
self._create_widgets(win, winner, final_playfield, local_mp)
self._display_widgets()

def _create_widgets(self, win:bool, winner, fp):
message = "You won the game!" if win else "It's a draw!\nThat's barely more than a loss." if winner == None else "You lost the game!"
def _create_widgets(self, win:bool, winner, fp, local_mp:bool):
if(not local_mp):
message = "You won the game!" if win else "It's a draw!\nThat's barely more than a loss." if winner == None else "You lost the game!"
else:
message = "It's a draw!" if winner == None else f"{winner.display_name} won the game!"
self.lblWinner = tk.Label(self, width=20, height=5, bg="white", text=message)
for i in range(3):
for j in range(3):
Expand All @@ -20,7 +23,7 @@ def _create_widgets(self, win:bool, winner, fp):
case 2:
fp[i][j] = "O"
case _:
fp[i][j] = " "
fp[i][j] = " "
self.lblPlayfield = tk.Label(self, width=20, height=5, bg="white", text=f'{fp[0][0]}|{fp[0][1]}|{fp[0][2]}\n_ _ _\n{fp[1][0]}|{fp[1][1]}|{fp[1][2]}\n_ _ _\n{fp[2][0]}|{fp[2][1]}|{fp[2][2]}')
self.btnMainMenu = tk.Button(self, text="Main Menu", width=20, height=5, command=lambda: self.master.show_menu())

Expand Down
10 changes: 6 additions & 4 deletions UI/field_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def _menu(self):
self.master.show_menu()

class field_controller():
def __init__(self, view, players, starting_uuid, **kwargs):
def __init__(self, view, players, starting_uuid, local_mp, **kwargs):
self.view = view
self.local_mp = local_mp
self.sub_controller = gamefield_controller(self.view.gamefield, starting_uuid, **kwargs)
for player_lbl, player in zip(self.view.player, players):
player_lbl.set(player.display_name, player_type.unknown, player.uuid)
Expand All @@ -115,7 +116,7 @@ def _menu(self):

def end(self, queue, *args):
root = self.view.master
root.show(EndScreen, queue['win'], queue['winner'], queue['final_playfield'])
root.show(EndScreen, queue['win'], queue['winner'], queue['final_playfield'], local_mp=self.local_mp)

def error(self, queue, *args):
root = self.view.master
Expand All @@ -130,8 +131,9 @@ def _close(self):
class Field(base_frame):
def __init__(self, master, chat, *args, starting_player, player1, player1_symbol, player2, player2_symbol, **kwargs):
super().__init__(master)
self._create_widgets(chat, display_chat=len(kwargs)==1)
self.controller = field_controller(self, [player1, player2], starting_player.uuid, **kwargs)
local_mp = not (len(kwargs)==1)
self._create_widgets(chat, display_chat=not local_mp)
self.controller = field_controller(self, [player1, player2], starting_player.uuid, local_mp, **kwargs)
self._display_widgets()
#self.bind("<<game/turn>>", self.controller.sub_controller.turn)
#self.bind("<<game/end>>", self.controller.end)
Expand Down

0 comments on commit 130ac46

Please sign in to comment.