squirrel-battle/dungeonbattle/interfaces.py

62 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2020-10-16 13:52:47 +00:00
class Map:
width: int
height: int
tiles: list
2020-10-16 13:52:47 +00:00
def __init__(self, width: int, height: int, tiles: list, entities: list):
self.width = width
self.height = height
self.tiles = tiles
2020-10-16 13:52:47 +00:00
self.entities = entities
@staticmethod
2020-10-09 16:24:13 +00:00
def load(filename: str):
with open(filename, "r") as f:
file = f.read()
return Map.load_from_string(file)
@staticmethod
2020-10-09 16:24:13 +00:00
def load_from_string(content: str):
lines = content.split("\n")
2020-10-09 16:24:13 +00:00
lines = [line for line in lines if line]
height = len(lines)
2020-10-09 16:24:13 +00:00
width = len(lines[0])
2020-10-16 13:52:47 +00:00
return Map(width, height, lines, [])
2020-10-11 13:24:51 +00:00
class Entity:
y: int
2020-10-11 13:24:51 +00:00
x: int
img: str
2020-10-11 13:24:51 +00:00
def __init__(self, y: int, x: int, img: str):
self.y = y
self.x = x
self.img = img
2020-10-09 16:24:13 +00:00
def move(self, x: int, y: int) -> None:
2020-10-11 13:24:51 +00:00
self.x = x
self.y = y
class FightingEntity(Entity):
maxhealth: int
health: int
strength: int
def __init__(self):
self.health = self.maxhealth
def hit(self, opponent) -> None:
opponent.take_damage(self, self.strength)
def take_damage(self, attacker, amount:int) -> None:
self.health -= amount
if self.health <= 0:
self.die()
def die(self) -> None:
pass