doku doku

This commit is contained in:
tovjemam 2023-11-22 21:38:47 +01:00
parent 5bccd0df77
commit c83499393a
5 changed files with 112 additions and 5 deletions

13
game.py
View File

@ -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)

View File

@ -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)

31
gui.py
View File

@ -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":

View File

@ -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}"

View File

@ -2,23 +2,50 @@ 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):