diff --git a/game.py b/game.py index bbe1985..1f74039 100644 --- a/game.py +++ b/game.py @@ -2,11 +2,24 @@ from gameobject import * from world import * class Game: + """ + Obsahuje logiku hry + + @Author: zbyv + @Date: 22.11.2023 + """ def __init__(self, world: World, hero: GameObject, home: GameObject): self.__world = world self.__hero = hero self.__home = home + """ + Spusti hru + + Returns: + True: hrdina dosel na domovskou pozici + False: hrdina se dostal na prazdne pole + """ def run(self) -> bool: gui = Gui(self.__world.width, self.__world.height) diff --git a/gameobject.py b/gameobject.py index bda2d84..45e2275 100644 --- a/gameobject.py +++ b/gameobject.py @@ -2,16 +2,37 @@ from vector2 import * from gui import * class GameObject: + """ + Dynamicky objekt + + @Author: zbyv + @Date: 22.11.2023 + """ def __init__(self, position: Vector2, symbol: str) -> None: self.__position = position self.__symbol = symbol + """ + Pozice objektu + """ @property def position(self): return self.__position + """ + Posune objekt zadanym vektorem + + Args: + direction: Vektor, o ktery se ma objekt posunout + """ def move(self, direction: Vector2): self.__position += direction + """ + Vykresli objekt na uvedenou instanci Gui + + Args: + gui: Gui, na ktere se ma objekt vykreslit + """ def draw(self, gui: Gui): gui.draw(self.__position.x, self.__position.y, self.__symbol) \ No newline at end of file diff --git a/gui.py b/gui.py index a1eb725..6489632 100644 --- a/gui.py +++ b/gui.py @@ -1,25 +1,52 @@ from vector2 import * class Gui: + """ + Zahrnuje funkcionalitu pro uzivatelsky vstup a vystup + + @Author: zbyv + @Date: 22.11.2023 + """ def __init__(self, width: int, height: int) -> None: self.__width = width self.__height = height # self.__data = None self.clear() - def draw(self, x: int, y: int, symbol: str): + """ + Nastavi zadany symbol na zadanou pozici + + Args: + x: `x` souradnice + y: `y` souradnice + symbol: znak pro vykresleni + """ + def draw(self, x: int, y: int, symbol: str) -> None: self.__data[x + y * self.__width] = symbol - def show(self): + """ + Vykresli cele herni pole + """ + def show(self) -> None: for y in range(self.__height): for x in range(self.__width): print(self.__data[x + y * self.__width], end="") print("") + """ + Vycisti cele herni pole + """ def clear(self): self.__data = [" " for _ in range(self.__width * self.__height)] + """ + Vyzada si od uzivatele smer pohybu + + Returns: + Vector2 reprezentujici zadany smer pohybu + """ + def input_direction(self) -> Vector2: match input("pohyb: "): case "2": diff --git a/vector2.py b/vector2.py index 84cb1ed..fee7617 100644 --- a/vector2.py +++ b/vector2.py @@ -1,25 +1,44 @@ from __future__ import annotations class Vector2: + """ + Dvojdimenzionalni vektor + + @Author: zbyv + @Date: 22.11.2023 + """ def __init__(self, x, y) -> None: self.__x = x self.__y = y + """ + `x` souradnice tohoto vektoru + """ @property def x(self): return self.__x + """ + `y` souradnice tohoto vektoru + """ @property def y(self): return self.__y + """ + Kouzelna metoda pro soucet vektoru + """ def __add__(self, other: Vector2) -> Vector2: return Vector2(self.x + other.x, self.y + other.y) + """ + Kouzelna metoda pro porovnani vektoru + """ def __eq__(self, other) -> bool: return self.x == other.x and self.y == other.y + """ + Kouzelna metoda pro prevod vektoru na str + """ def __str__(self) -> str: return f"{self.x}; {self.y}" - - \ No newline at end of file diff --git a/world.py b/world.py index 4722ec4..e8b4e58 100644 --- a/world.py +++ b/world.py @@ -2,24 +2,51 @@ from gui import * from vector2 import * class World: + """ + Staticky herni svet + + @Author: zbyv + @Date: 22.11.2023 + """ def __init__(self, data: list[list[int]], symbols: list[str]) -> None: self.__width = len(data[0]) self.__height = len(data) self.__data = data self.__symbols = symbols + """ + Sirka sveta + """ @property def width(self): return self.__width + """ + Vyska sveta + """ @property def height(self): return self.__height + """ + Zjisti, jestli je policko na zadane pozici prazdne. + + Args: + position: Pozice pro kontrolu + + Returns: + True pokud je policko prazdne, jinak False + """ def is_empty(self, position: Vector2): return self.__data[position.y][position.x] == 0 + """ + Vykresli svet na zadanou instanci Gui + + Args: + gui: Gui, na ktere se svet vykresli + """ def draw(self, gui: Gui) -> None: for y in range(self.height): for x in range(self.width): - gui.draw(x, y, self.__symbols[self.__data[y][x]]) \ No newline at end of file + gui.draw(x, y, self.__symbols[self.__data[y][x]])