From 0e8f804c7191dce95b7d712e5abf31b25f21d65a Mon Sep 17 00:00:00 2001 From: Hauke Platte Date: Mon, 18 Mar 2024 00:50:24 +0100 Subject: [PATCH] feat(UI-UX): add draw message and final playfield to endscreen [TTTK-83] --- UI/endscreen.py | 23 ++++++++++++++++------- UI/field_frame.py | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/UI/endscreen.py b/UI/endscreen.py index b43f82c..2f72c84 100644 --- a/UI/endscreen.py +++ b/UI/endscreen.py @@ -4,18 +4,27 @@ #from .field_frame import Field class EndScreen(base_frame): - def __init__(self, master, win:bool, *args, **kwargs): + def __init__(self, master, win:bool, winner, final_playfield, *args, **kwargs): super().__init__(master) - self._create_widgets(win) + self._create_widgets(win, winner, final_playfield) self._display_widgets() - def _create_widgets(self, win:bool): - message = "You won the game!" if win else "You lost the game!" + 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!" self.lblWinner = tk.Label(self, width=20, height=5, bg="white", text=message) - #self.btnPlayAgain = tk.Button(self, width=20, height=5, text="Play Again", command=lambda: self.master.show(Field)) + for i in range(3): + for j in range(3): + match fp[i][j]: + case 1: + fp[i][j] = "X" + case 2: + fp[i][j] = "O" + case _: + 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()) def _display_widgets(self): - self.lblWinner.pack() - #self.btnPlayAgain.pack() + self.lblWinner.pack(fill=tk.X) + self.lblPlayfield.pack() self.btnMainMenu.pack() \ No newline at end of file diff --git a/UI/field_frame.py b/UI/field_frame.py index f7d7a6c..152fee8 100644 --- a/UI/field_frame.py +++ b/UI/field_frame.py @@ -112,7 +112,7 @@ def _menu(self): def end(self, queue, *args): root = self.view.master - root.show(EndScreen, queue['win']) + root.show(EndScreen, queue['win'], queue['winner'], queue['final_playfield']) def error(self, queue, *args): root = self.view.master