def test_start_fight(self): h = self.hero e = self.enemy h.learn_spell(Spell()) h.equip_weapon(Weapon()) ft = Fight(h, e) ft.start_fight()
def do_you_wanna_start_a_fight(): if d.hero_attack(by="spell") is True: des = input( "There is an enemy in the range of your spell. You can start a fight. (y/n) ") if des == "y": ran = h.spell.get_cast_range() enemy = Enemy.generate_enemy() enemy_coords = check_for_stuff( d.dungeon_map, d.x, d.y, "E", ran) f = Fight(h, enemy, enemy_coords, d.dungeon_map) f.start_fight() elif des == "n": dir = get_right_direction() d.move_hero(dir) elif d.hero_attack(by="weapon") is True: des = input( "There is an enemy near you. You can start a fight. (y/n) ") if des == "y": enemy = Enemy.generate_enemy() enemy_coords = check_for_stuff(d.dungeon_map, d.x, d.y, "E", 1) f = Fight(h, enemy, enemy_coords, d.dungeon_map) f.start_fight() elif des == "n": dir = get_right_direction() d.move_hero(dir)
def next_step(self, row, col): if self.in_map(row, col): if self.symbol_in_map(row, col) is 'G': print("Congrats you are goint to the next level") return True elif self.symbol_in_map(row, col) is '#': print("Cannot move in this direction because of obstacle") return False elif self.symbol_in_map(row, col) is 'E': enemy = Enemy() battle = Fight(self.hero, enemy) battle.start_fight() return True elif self.symbol_in_map(row, col) is 'T': print("You found a treasury") s = Spell() self.hero.learn_spell(s) return True else: return True else: print("Out of map") return False
def move_hero(self, direction): rows = len(self.matrix) cols = len(self.matrix[0]) for i in range(rows): for j in range(cols): if self.matrix[i][j] == 'H': if direction == 'left': if self.valid_position(i, j - 1): if self.matrix[i][j - 1] is '.': self.matrix[i][j - 1] = 'H' self.matrix[i][j] = '.' return True if self.matrix[i][j - 1] == 'E': fight = Fight(self.hero, enemy) if fight.start_fight(): self.matrix[i][j - 1] = 'H' self.matrix[i][j] = '.' return True else: return "Game Over" if self.matrix[i][j] == 'T': print('Found treasure!') self.matrix[i][j - 1] = 'H' self.matrix[i][j] = '.' hero_treasure = self.pick_treasure() if hero_treasure == 'health': self.hero.healt.take_healing(self.treasure['healt']) else: self.hero.mana += self.treasure['mana'] else: return False elif direction == 'right': if self.valid_position(i, j + 1): if self.matrix[i][j + 1] is '.': self.matrix[i][j + 1] = 'H' self.matrix[i][j] = '.' return True elif self.matrix[i][j + 1] == 'E': fight = Fight(self.hero, enemy) if fight.start_fight(): self.matrix[i][j + 1] = 'H' self.matrix[i][j] = '.' return True else: return "Game Over" elif self.matrix[i][j + 1] == 'T': print('Found treasure!') self.matrix[i][j + 1] = 'H' self.matrix[i][j] = '.' hero_treasure = self.pick_treasure() if hero_treasure == 'health': self.hero.take_healing(self.treasure['health']) else: self.hero.mana += self.treasure['mana'] print('Mana', self.hero.get_mana()) else: return False if direction == 'up': if self.valid_position(i - 1, j): if self.matrix[i - 1][j] is '.': self.matrix[i - 1][j] = 'H' self.matrix[i][j] = '.' return True elif self.matrix[i - 1][j] == 'E': fight = Fight(self.hero, enemy) if fight.start_fight(): elf.matrix[i - 1][j] = 'H' self.matrix[i][j] = '.' return True else: return "Game Over" elif self.matrix[i - 1][j] == 'T': print('Found treasure!') self.matrix[i - 1][j] = 'H' self.matrix[i][j] = '.' hero_treasure = self.pick_treasure() if hero_treasure == 'health': self.hero.take_healing(self.treasure['health']) else: self.hero.mana += self.treasure['mana'] else: return False elif direction == 'down': if self.valid_position(i + 1, j): if self.matrix[i + 1][j] is '.': self.matrix[i + 1][j] = 'H' self.matrix[i][j] = '.' return True elif self.matrix[i + 1][j] == 'E': fight = Fight(self.hero, enemy) if fight.start_fight(): self.matrix[i + 1][j] = 'H' self.matrix[i][j] = '.' return True else: return "Game Over" elif self.matrix[i + 1][j] == 'T': print('Found treasure!') self.matrix[i + 1][j] = 'H' self.matrix[i][j] = '.' hero_treasure = self.pick_treasure() if hero_treasure == 'health': self.hero.healt.take_healing(self.treasure['healt']) else: self.hero.mana += self.treasure['mana'] else: return False