Skip to content

Commit

Permalink
doc(UI-UX): add class header for documentation purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
HOOK-Hawkins committed Mar 18, 2024
1 parent b7544ba commit f93b79f
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions UI/base_frame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import tkinter as tk

class base_frame(tk.Frame):
"""
Base class for all frames in the game. This class is used to set the background color of all frames to white.
"""
def __init__(self, parent):
tk.Frame.__init__(self, parent, bg='#FFFFFF')
4 changes: 4 additions & 0 deletions UI/chat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from .lib import tttk_tk as tk

class Chat(tk.Frame):
"""
Chat window for the game. This class is used to display the chat window and send messages to the server.
It also listens for incoming chat messages from the server.
"""
def __init__(self, master, root, chat='', *args, **kwargs):
super().__init__(master)
self.root = root
Expand Down
5 changes: 5 additions & 0 deletions UI/credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from .base_frame import base_frame

class Credits(base_frame):
"""
The credits screen of the game. This screen is used to display the names of the developers of the game.
It also contains a hidden developer options menu. This menu can be accessed by clicking the "created by" label
three times. This menu is used to test the game and is not intended for the end user.
"""
def __init__(self, master, *args, **kwargs):
super().__init__(master)
self._create_widgets()
Expand Down
4 changes: 4 additions & 0 deletions UI/customLobby.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def clear(self):
self.master.clear(self.slot)

class CustomLobby(base_frame):
"""
Custom lobby for the game. This class is used to display the custom lobby window and send messages to the server.
It is only used for internal testing.
"""
def __init__(self, master, *args):
super().__init__(master)
self.player = list()
Expand Down
3 changes: 3 additions & 0 deletions UI/endscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def too_dark(hex_color: str):
return (r+g+b)/3 < 85

class EndScreen(base_frame):
"""
The end screen is displayed after a game has ended. It shows the winner and the final playfield.
"""
def __init__(self, master, win:bool, winner, final_playfield, *args, local_mp=False, **kwargs):
super().__init__(master)
self._create_widgets(win, winner, final_playfield, local_mp)
Expand Down
15 changes: 15 additions & 0 deletions UI/field_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
from .statistics import Statistics

class player_type(Enum):
"""
Enum for the different player types
"""
local = auto()
ai_weak = auto()
ai_strong = auto()
network = auto()
unknown = auto()

class player(tk.Container):
"""
Class for the player labels in the gamefield
"""
def __init__(self, master, number, uuid=None):
super().__init__(master)
self.uuid = uuid
Expand Down Expand Up @@ -59,6 +65,9 @@ def _display_widgets(self):
self.symbol.grid(row=1, column=1)

class game_menu(base_frame):
"""
The game menu can be accessed from the gamefield. It allows the user to return to the main menu, the statistics or to exit the game.
"""
def __init__(self, master, *args, **kwargs):
super().__init__(master)
self._create_widgets()
Expand Down Expand Up @@ -93,6 +102,9 @@ def _menu(self):
self.master.show_menu()

class field_controller():
"""
The controller for the gamefield. It is used to control the gamefield and access the game menu.
"""
def __init__(self, view, players, player_symbols, starting_uuid, local_mp, **kwargs):
self.view = view
self.local_mp = local_mp
Expand Down Expand Up @@ -124,6 +136,9 @@ def _close(self):
self.view.master.show_menu()

class Field(base_frame):
"""
The field frame is used to display the gamefield and the player labels.
"""
def __init__(self, master, chat, *args, starting_player, player1, player1_symbol, player2, player2_symbol, **kwargs):
super().__init__(master)
local_mp = not (len(kwargs)==1)
Expand Down
6 changes: 6 additions & 0 deletions UI/gamefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class input_methods(Enum):
uom= auto()

class gamefield(tk.Frame):
"""
Class for the gamefield in the game. This class is used to display the gamefield
"""
def __init__(self, master):
super().__init__(master)
self._create_widgets()
Expand All @@ -26,6 +29,9 @@ def _display_widgets(self):
field.grid(sticky=tk.N+tk.S+tk.E+tk.W, row=position[0], column=position[1])

class gamefield_controller:
"""
Class for the gamefield controller in the game. This class is used to control the gamefield
"""
def __init__(self, view: gamefield, starting_uuid: UUID, symbol_colors, **kwargs):
self.view = view
self.currentplayer = starting_uuid
Expand Down
4 changes: 4 additions & 0 deletions UI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from Client.profile_save import Profile as ProfileIO

class Root(tk.Tk):
"""
Root class for the application. This class is the main window and handles the switching of frames.
It also handles the network events and the queues for the network events.
"""
def __init__(self):
super().__init__()
start_width = 500
Expand Down
3 changes: 3 additions & 0 deletions UI/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from .credits import Credits

class Menu(base_frame):
"""
The main menu of the game. This screen is used to navigate to the different parts of the game.
"""
def __init__(self, master, *args, **kwargs):
super().__init__(master)
self._create_widgets()
Expand Down
3 changes: 3 additions & 0 deletions UI/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


class messages:
"""
Class for the different message boxes
"""
def __init__(self, type : str = "error", message : str = None):
""""
Constructor for the messages class
Expand Down
13 changes: 13 additions & 0 deletions UI/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from .statistics import Statistics

class Join(base_frame):
"""
Class for the join screen. This screen is used to join a lobby and to display the players in the lobby.
"""
def __init__(self, master, *args, opponent=player_type.unknown, local_players, quiet=False, **kwargs):
super().__init__(master)
self.quiet = quiet
Expand Down Expand Up @@ -105,6 +108,9 @@ def _show_statistics(self):
self.master.show(Statistics, return_to=Join)

class LocalProfileSelection(base_frame):
"""
Class for the local profile selection screen. This screen is used to select the local profiles for the game.
"""
def __init__(self, master, *args, **kwargs):
super().__init__(master)
self._create_widgets()
Expand Down Expand Up @@ -175,6 +181,9 @@ def _start_game(self):
self.master.show(Join, display=False, opponent=player_type.local, local_players=[player1.uuid, player2.uuid],quiet=True)

class Lobby_Overview(tk.Container):
"""
Class for the lobby overview. This screen is part of the multiplayer screen and used to display the available lobbies and to join them.
"""
def __init__(self, master):
super().__init__(master)
self._create_widgets()
Expand Down Expand Up @@ -235,6 +244,10 @@ def on_destroy(self):
del self.master.master.network_events['lobby/connect_error']

class Multiplayer(base_frame):
"""
Class for the multiplayer screen. This screen is used to select the multiplayer mode and to create or join lobbies.
It houses the lobby overview.
"""
def __new__(cls, master, *args, **kwargs):
if(len(master.players) == 0 or master.player == None):
return Profile(master, *args, return_to=Multiplayer, **kwargs)
Expand Down
6 changes: 6 additions & 0 deletions UI/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from .messages import messages

class NewProfile(base_frame):
"""
Class for the creation of a new profile. This class is used to create a new profile or edit an existing one.
"""
def __init__(self, master, *args, **kwargs):
super().__init__(master)
self.color_str = None
Expand Down Expand Up @@ -87,6 +90,9 @@ def _color(self):
self.btnColor.config(bg=self.color_str)

class Profile(base_frame):
"""
Class for the profile selection. This class is used to select a profile for the game.
"""
def __new__(cls, master, *args, **kwargs):
if len(master.players) == 0:
return NewProfile(master, *args, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions UI/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from .profile import Profile

class Singleplayer(base_frame):
"""
The singleplayer menu. This screen is used to choose the opponent for a singleplayer game.
"""
def __new__(cls, master, *args, **kwargs):
if(len(master.players) == 0 or master.player == None):
return Profile(master, *args, return_to=Singleplayer, **kwargs)
Expand Down
6 changes: 6 additions & 0 deletions UI/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from Server.player import Player

class Statistics_data(tk.Container):
"""
Class for the statistics data in the statistics frame. This class is used to display the statistics of the players.
"""
def __init__(self, master, *args, **kwargs):
super().__init__(master)

Expand All @@ -16,6 +19,9 @@ def _update_statistics(self, queue):
tk.Label(self, text=value).grid(sticky=tk.E+tk.W+tk.N+tk.S, column=j+1, row=i)

class Statistics(base_frame):
"""
The statistics menu. This screen is used to display the statistics of the players.
"""
def __init__(self, master, return_to, *args, **kwargs):
super().__init__(master)
self.return_to = return_to
Expand Down

0 comments on commit f93b79f

Please sign in to comment.