A basic fighting mechanic and a few entities
This commit is contained in:
		
							
								
								
									
										0
									
								
								dungeonbattle/entities/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								dungeonbattle/entities/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										5
									
								
								dungeonbattle/entities/monsters.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								dungeonbattle/entities/monsters.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					from ..interfaces import FightingEntity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Squirrel(FightingEntity):
 | 
				
			||||||
 | 
					    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
 | 
				
			||||||
@@ -50,3 +50,22 @@ class Entity:
 | 
				
			|||||||
    def move(self, x: int, y: int) -> None:
 | 
					    def move(self, x: int, y: int) -> None:
 | 
				
			||||||
        self.tile.x = x
 | 
					        self.tile.x = x
 | 
				
			||||||
        self.tile.y = y
 | 
					        self.tile.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 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user