typy vole

This commit is contained in:
tovjemam 2023-11-22 21:43:16 +01:00
parent c83499393a
commit 6d276939b0
5 changed files with 15 additions and 12 deletions

View File

@ -8,7 +8,7 @@ class Game:
@Author: zbyv
@Date: 22.11.2023
"""
def __init__(self, world: World, hero: GameObject, home: GameObject):
def __init__(self, world: World, hero: GameObject, home: GameObject) -> None:
self.__world = world
self.__hero = hero
self.__home = home

View File

@ -16,7 +16,7 @@ class GameObject:
Pozice objektu
"""
@property
def position(self):
def position(self) -> Vector2:
return self.__position
"""
@ -25,7 +25,7 @@ class GameObject:
Args:
direction: Vektor, o ktery se ma objekt posunout
"""
def move(self, direction: Vector2):
def move(self, direction: Vector2) -> None:
self.__position += direction
"""
@ -34,5 +34,5 @@ class GameObject:
Args:
gui: Gui, na ktere se ma objekt vykreslit
"""
def draw(self, gui: Gui):
def draw(self, gui: Gui) -> None:
gui.draw(self.__position.x, self.__position.y, self.__symbol)

2
gui.py
View File

@ -37,7 +37,7 @@ class Gui:
"""
Vycisti cele herni pole
"""
def clear(self):
def clear(self) -> None:
self.__data = [" " for _ in range(self.__width * self.__height)]
"""

View File

@ -7,7 +7,7 @@ class Vector2:
@Author: zbyv
@Date: 22.11.2023
"""
def __init__(self, x, y) -> None:
def __init__(self, x: int, y: int) -> None:
self.__x = x
self.__y = y
@ -15,14 +15,14 @@ class Vector2:
`x` souradnice tohoto vektoru
"""
@property
def x(self):
def x(self) -> int:
return self.__x
"""
`y` souradnice tohoto vektoru
"""
@property
def y(self):
def y(self) -> int:
return self.__y
"""
@ -34,7 +34,10 @@ class Vector2:
"""
Kouzelna metoda pro porovnani vektoru
"""
def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Vector2):
return NotImplemented
return self.x == other.x and self.y == other.y
"""

View File

@ -18,14 +18,14 @@ class World:
Sirka sveta
"""
@property
def width(self):
def width(self) -> int:
return self.__width
"""
Vyska sveta
"""
@property
def height(self):
def height(self) -> int:
return self.__height
"""
@ -37,7 +37,7 @@ class World:
Returns:
True pokud je policko prazdne, jinak False
"""
def is_empty(self, position: Vector2):
def is_empty(self, position: Vector2) -> bool:
return self.__data[position.y][position.x] == 0
"""