Merge branch 'master' into game.
This commit is contained in:
		
							
								
								
									
										0
									
								
								dungeonbattle/entities/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								dungeonbattle/entities/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										33
									
								
								dungeonbattle/entities/items.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								dungeonbattle/entities/items.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					from ..interfaces import Entity, FightingEntity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Item(Entity):
 | 
				
			||||||
 | 
					    held:bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __init__(self, *args, **kwargs):
 | 
				
			||||||
 | 
					        super().__init__(self, *args, **kwargs)
 | 
				
			||||||
 | 
					        self.held = False
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def drop(self, x:int, y:int):
 | 
				
			||||||
 | 
					        self.held = False
 | 
				
			||||||
 | 
					        self.move(x, y)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def hold(self):
 | 
				
			||||||
 | 
					        self.held = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Bomb(Item):
 | 
				
			||||||
 | 
					    damage:int = 5
 | 
				
			||||||
 | 
					    exploding:bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __init__(self, *args, **kwargs):
 | 
				
			||||||
 | 
					        super().__init__(self, *args, **kwargs)
 | 
				
			||||||
 | 
					        self.exploding = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def drop(self, x:int, y:int):
 | 
				
			||||||
 | 
					        super.drop(self, x, y)
 | 
				
			||||||
 | 
					        self.exploding = True
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def act(self, map):
 | 
				
			||||||
 | 
					        if self.exploding:
 | 
				
			||||||
 | 
					            for e in map.entities:
 | 
				
			||||||
 | 
					                if abs (e.x - self.x) + abs (e.y - self.y) <= 1 and isinstance(e,FightingEntity):
 | 
				
			||||||
 | 
					                    e.take_damage(self, self.damage)
 | 
				
			||||||
							
								
								
									
										9
									
								
								dungeonbattle/entities/monsters.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								dungeonbattle/entities/monsters.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					from ..interfaces import FightingEntity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Monster(FightingEntity):
 | 
				
			||||||
 | 
					    def act(self, map):
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Squirrel(Monster):
 | 
				
			||||||
 | 
					    maxhealth = 10
 | 
				
			||||||
 | 
					    strength = 3
 | 
				
			||||||
							
								
								
									
										5
									
								
								dungeonbattle/entities/player.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								dungeonbattle/entities/player.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					from ..interfaces import FightingEntity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Player(FightingEntity):
 | 
				
			||||||
 | 
					    maxhealth = 20
 | 
				
			||||||
 | 
					    strength = 5
 | 
				
			||||||
@@ -11,7 +11,7 @@ class Map:
 | 
				
			|||||||
    height: int
 | 
					    height: int
 | 
				
			||||||
    tiles: list
 | 
					    tiles: list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, width: int, height: int, tiles: list, entities: list):
 | 
					    def __init__(self, width: int, height: int, tiles: list, entities = []):
 | 
				
			||||||
        self.width = width
 | 
					        self.width = width
 | 
				
			||||||
        self.height = height
 | 
					        self.height = height
 | 
				
			||||||
        self.tiles = tiles
 | 
					        self.tiles = tiles
 | 
				
			||||||
@@ -37,8 +37,10 @@ class Map:
 | 
				
			|||||||
        width = len(lines[0])
 | 
					        width = len(lines[0])
 | 
				
			||||||
        tiles = [[Tile(c)
 | 
					        tiles = [[Tile(c)
 | 
				
			||||||
                  for x, c in enumerate(line)] for y, line in enumerate(lines)]
 | 
					                  for x, c in enumerate(line)] for y, line in enumerate(lines)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return Map(width, height, tiles, [])
 | 
					        return Map(width, height, tiles, [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def draw_string(self) -> str:
 | 
					    def draw_string(self) -> str:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Draw the current map as a string object that can be rendered
 | 
					        Draw the current map as a string object that can be rendered
 | 
				
			||||||
@@ -64,15 +66,31 @@ class Tile(Enum):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Entity:
 | 
					class Entity:
 | 
				
			||||||
    y: int
 | 
					 | 
				
			||||||
    x: int
 | 
					    x: int
 | 
				
			||||||
    img: str
 | 
					    y: int
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def __init__(self, y: int, x: int, img: str):
 | 
					 | 
				
			||||||
        self.y = y
 | 
					 | 
				
			||||||
        self.x = x
 | 
					 | 
				
			||||||
        self.img = img
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def move(self, x: int, y: int) -> None:
 | 
					    def move(self, x: int, y: int) -> None:
 | 
				
			||||||
        self.x = x
 | 
					        self.x = x
 | 
				
			||||||
        self.y = y
 | 
					        self.y = y
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def act(self, m:Map):
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user