Exemplo n.º 1
0
 def setUp(self):
     self.hero = Hero("Gosho", 30, "Goshko")
     self.orc = Orc("Pesho", 100, 1.3)
     self.fight = Fight(self.hero, self.orc)
     self.weapon = Weapon("qax", 40, 0.3)
     self.hero.weapon = self.weapon
     self.orc.weapon = self.weapon
Exemplo n.º 2
0
 def test_fight_simulation(self):
     hero = Hero("Natsu", 10000, "DragonSlayer")
     orc = Orc("BadOrc", 100, 2)
     fight = Fight(hero, orc)
     dragonpower = Weapon("Dragonpower", 200, 0.8)
     axe = Weapon("Axe", 120, 0.4)
     fight.hero.weapon = dragonpower
     fight.orc.weapon = axe
     fight.simulate_fight()
     self.assertEqual(fight.orc.battlehp, 0)
     self.assertTrue(fight.hero.battlehp > 0)
Exemplo n.º 3
0
 def test_fight_simulation(self):
     hero = Hero("Natsu", 10000, "DragonSlayer")
     orc = Orc("BadOrc", 100, 2)
     fight = Fight(hero, orc)
     dragonpower = Weapon("Dragonpower", 200, 0.8)
     axe = Weapon("Axe", 120, 0.4)
     fight.hero.weapon = dragonpower
     fight.orc.weapon = axe
     fight.simulate_fight()
     self.assertEqual(fight.orc.battlehp, 0)
     self.assertTrue(fight.hero.battlehp > 0)
 def test_start_fight(self):
     f = Fight()
     h = Hero("Geralt", "White wolf", 100, 100, 5)
     h.equip(Weapon("Axe", 40))
     h.learn(Spell("Storm", 30, 50, 3))
     e = Enemy(100, 200, 30)
     e.equip(Weapon("Sword", 40))
     e.learn(Spell("Fire", 30, 20, 3))
     d = 2
     h = f.start_fight(h, e, d)
     print('=======================')
     print(h.known_as(), h.get_health())
class TestFightClass(unittest.TestCase):
    def setUp(self):
        self.hero = Hero('Arthas', 3500, 'Lich King')
        self.orc = Orc('Garrosh', 3500, 1.2)
        self.frostmourne = Weapon('Sword', 250, 0.8)
        self.gorehowl = Weapon('Axe', 350, 0.2)
        self.hero.equip_weapon(self.frostmourne)
        self.orc.equip_weapon(self.gorehowl)

        self.fight = Fight(self.hero, self.orc)

    def test_initialing(self):
        self.assertIsInstance(self.fight.hero, Hero)
        self.assertIsInstance(self.fight.orc, Orc)

    def test_who_is_first(self):
        first = []
        for i in range(10):
            self.fight = Fight(self.hero, self.orc)
            first.append(self.fight.first)

        flag = [False, False]
        for i in first:
            if isinstance(i, Hero):
                flag[0] = True
            elif isinstance(i, Orc):
                flag[1] = True

        self.assertEqual(flag, [True, True])

    def test_simulate_fight_Hero_Wins(self):
        self.orc = Orc('Gul Dan', 500, 1)
        self.fight = Fight(self.hero, self.orc)
        self.assertEqual(self.fight.simulate_fight(), 'hero wins')

    def test_simulate_fight_Orc_Wins(self):
        self.hero = Hero('Tirion', 500, 'The AshBringer')
        self.fight = Fight(self.hero, self.orc)
        self.assertEqual(self.fight.simulate_fight(), 'orc wins')

    def test_simulate_first_wins(self):
        self.hero = Hero('Tirion', 1000, 'The AshBringer')
        self.orc = Orc('Gul Dan', 1000, 1)
        weapon = Weapon('Sword', 200, 0)
        self.hero.equip_weapon(weapon)
        self.orc.equip_weapon(weapon)
        self.fight = Fight(self.hero, self.orc)
        if isinstance(self.fight.first, Hero):
            winer = 'hero wins'
        else:
            winer = 'orc wins'
        self.assertEqual(self.fight.simulate_fight(), winer)
Exemplo n.º 6
0
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        self.dungeon = None
        self.hero = None

        self.left_pressed = False
        self.right_pressed = False
        self.up_pressed = False
        self.down_pressed = False
        self.move_char = (".", [0, 0])
        self.fight = Fight()
        arcade.set_background_color((59, 68, 75))
Exemplo n.º 7
0
    def fight(self, output, player1, player2, p1name, p2name, pos1, pos2, ind1, path):
        fight = Fight(player1, player2)
        winner = fight.simulate_fight()
        if winner == player1:
            output[pos1] = "."
            output[pos2] = ind1
            del self.spawnlist[p2name]
            self.spawnedplayers.remove(p2name)
        elif winner == player2:
            output[pos1] = "."
            del self.spawnlist[p1name]
            self.spawnedplayers.remove(p1name)

        self.reinitialize_file(path, output)
 def setUp(self):
     self.pudge = Hero()
     self.magic = Spell(mana_cost=5, damage=33)
     self.sword = Weapon(damage=30)
     self.pudge.learn(self.magic)
     self.pudge.equip(self.sword)
     self.battle = Fight(self.pudge, (4, 6), (4, 5), 'walk')
Exemplo n.º 9
0
    def doPoll(self):

        oneDay = 60*60*24
        startTime = (time.time() - 7*oneDay) * 1000
        reports = self.api.getReports(startTime).json()
        if (len(reports) == 0):
            return

        for report in reports:
            id = report['id']
            fights = self.api.getFights(id)
            if not report['id'] in self.data.reports.keys():
                self.data.reports[id] = Report(
                    id,
                    report['title'],
                    report['owner'],
                    int(report['start']))
                print("New log!")
            if len(self.data.reports[id].fights) < len(fights):
                print("New fight!")
                self.data.reports[id].dirty = True
                for fight in fights:
                    fightId = fight['id']
                    if not fightId in self.data.reports[id].fights.keys():
                        newFight = Fight(fightId, fight['name'],id)
                        self.data.reports[id].addFight(newFight)
            for id, report in self.data.reports.items():
                if report.isDirty():
                    self.data.reports[id].message = report.getFormattedChatMessage()
                if report.startTime < (time.time() - 14*oneDay) * 1000:
                    self.data.reports.pop(id, None)
Exemplo n.º 10
0
    def __init__(self, text_file , lootListPath):
        self.matrix = []
        with open(str(text_file)) as f:
            self.matrix = f.readlines()
        self.matrix = [x.strip() for x in self.matrix]
        self.hero = None
        self.fight = Fight()
        self.borders = [len(self.matrix), len(self.matrix[0])]
        self.hero_place = []
        self.end_of_game = False
        enemy = Enemy(100, 120, 20)
        enemy.equip(Weapon("Sword", 40))
        enemy.learn(Spell("Fire", 30, 20, 3))
        self.enemies = [enemy, Enemy(70, 70, 15), Enemy(50, 50, 10)]
        self.treasure = [Weapon("Axe", 35), Spell("FireStorm", 40, 20, 3), ["h", 20], ["h", 30]]

        self.loot_dict = self.__class__.extract_loot_dictionary(lootListPath)
Exemplo n.º 11
0
class Test_Fight(unittest.TestCase):
    def setUp(self):
        self.testOrc = Orc("TestOrc", 100, 1.4)
        self.testHero = Hero("TestHero", 100, "Tester")
        self.testOrc.weapon = Weapon("TestBrick", 30, 0.3)
        self.testHero.weapon = Weapon("TestOrcSlapper", 50, 0.6)
        self.testFight = Fight(self.testOrc, self.testHero)

    def test_simulate_fight(self):
        result = self.testFight.simulate_fight()
        self.assertIn(result, [self.testOrc, self.testHero])

    def test_simulate_fight_with_no_weapons_equipped(self):
        self.testOrc.weapon = None
        self.testHero.weapon = None
        result = self.testFight.simulate_fight()
        self.assertEqual(result, "No winner")
Exemplo n.º 12
0
class TestFight(unittest.TestCase):

    def setUp(self):
        self.hero = Hero("Gosho", 30, "Goshko")
        self.orc = Orc("Pesho", 100, 1.3)
        self.fight = Fight(self.hero, self.orc)
        self.weapon = Weapon("qax", 40, 0.3)
        self.hero.weapon = self.weapon
        self.orc.weapon = self.weapon

    def test_simulate_fight(self):
        self.fight.simulate_fight()
        self.assertFalse(self.orc.is_alive() and self.hero.is_alive())

    def test_simulate_fight_orc_no_weapon(self):
        self.fight.simulate_fight()
        self.orc.weapon = None
        self.assertFalse(self.orc.is_alive() and self.hero.is_alive())
Exemplo n.º 13
0
 def fight (self,isboss):
     fight_handler = Fight()
     a = True
     #This is the natural regeneration... it only happens when you go into combat, so you can't abuse it by walking between already/cleared areas
     self.my_adventurer.regenerate()
     
     if isboss == False :
         monster = Monster(self.my_adventurer.level)
     elif isboss == True:
         monster = boss(self.my_adventurer.level)
     
     if self.my_adventurer.current_hp > 0 :
         
         a =  fight_handler.fight_calcuation(self.my_adventurer, monster)
         if a ==False :
             quit() 
     else :
         print "You shouldn't see this ever..."
    def setUp(self):
        self.hero = Hero('Arthas', 3500, 'Lich King')
        self.orc = Orc('Garrosh', 3500, 1.2)
        self.frostmourne = Weapon('Sword', 250, 0.8)
        self.gorehowl = Weapon('Axe', 350, 0.2)
        self.hero.equip_weapon(self.frostmourne)
        self.orc.equip_weapon(self.gorehowl)

        self.fight = Fight(self.hero, self.orc)
Exemplo n.º 15
0
def main():
    h = Hero("Bron", "Dragonslayer", 100, 100, 2)
    w = Weapon("The Axe of Destiny", 20)
    h.equip(w)
    s = Spell("Fireball", 20, 50, 2)
    h.learn(s)
    map = Dungeon("map.txt")
    map.open_map()
    map.spawn(h)
    map.move_hero("right")
    map.move_hero("down")
    map.move_hero("down")
    map.move_hero("down")
    map.print_map()
    fight = Fight(map, h)
    fight.hero_attack(by="spell")
    map.respawn()
    map.get_map()
Exemplo n.º 16
0
 def test_when_Hero_Loose(self):
     w = Weapon(name="The Axe of Destiny", damage=20)
     h = Hero(name="Bron",
              title="Dragonslayer",
              health=100,
              mana=100,
              mana_regeneration_rate=2)
     self.assertEqual(
         False,
         Fight().fight_simulator(h, Enemy(1, 10, 100), 0, 'up'))
Exemplo n.º 17
0
 def start(self):
     old_players = {} # an string-Player dict
     result = {}
     for row in self.candidates:
         new_player = Player(row['Name'], int(row['Health']), int(row['Damage']), int(row['Attacks']))
         for pname in old_players:
             f = Fight(old_players[pname], new_player)
             winner = f.fight()
             print '\n##########################################\n'
             # sleep(1)
             if result.has_key(winner):
                 result[winner] += 1
             else:
                 result[winner] = 1
         # add new player to the old player list
         old_players[row['Name']] = new_player
     result = sorted(result.items(), key=operator.itemgetter(1), reverse=True)
     print 'Number of winnings: '+str(result)
     print 'Final winner is '+result[0][0]
	def __init__(self, grid_size, hero_instance):
		self.map_size = grid_size
		self.map = map(grid_size=self.map_size)
		self.hero = hero_instance
		self.ai = AI_class(hero_instance=self.hero, map_instance=self.map)
		self.fight = Fight(hero=self.hero, is_Ai=True)
		self.room = room()
		self.round_count = 0
		self.game_active = True
		self.round_max = 5
		self.stop_value = self.map_size**2
 def test_simulate_first_wins(self):
     self.hero = Hero('Tirion', 1000, 'The AshBringer')
     self.orc = Orc('Gul Dan', 1000, 1)
     weapon = Weapon('Sword', 200, 0)
     self.hero.equip_weapon(weapon)
     self.orc.equip_weapon(weapon)
     self.fight = Fight(self.hero, self.orc)
     if isinstance(self.fight.first, Hero):
         winer = 'hero wins'
     else:
         winer = 'orc wins'
     self.assertEqual(self.fight.simulate_fight(), winer)
Exemplo n.º 20
0
 def __battle_helper(challenger: Fighter, opponent: Fighter,
                     skill: str) -> None:
     """
     Serves as a "bridge" between Fighter and Fight classes and determines
     who the winner/loser from a fight is. This method should not be
     accessed outside of this class.
     :param challenger: Fighter involved in battle
     :param opponent: Fighter involved in battle
     :param skill: skill to be fought with
     :return: None
     """
     from Fight import Fight
     challenger_skill = challenger.__skills.get(skill)
     opponent_skill = opponent.__skills.get(skill)
     fight = Fight(challenger, opponent, challenger_skill, opponent_skill)
     fight.fight()
     challenger.__has_fought = True
     opponent.__has_fought = True
     Fighter.__prizes(skill, fight.winner, fight.loser)
     print(fight.winner)
     print(fight.loser)
Exemplo n.º 21
0
def worker(matchups):
    global lock, total_games_played, total_games_skipped, player_classes, games_won, games_played
    for i, game_players in enumerate(matchups):
        # print(f"Games between {game_players[0]} and {game_players[1]}")
        games_count = 0
        last_winner = None
        consecutive_wins = 0
        while games_count < games_per_matchup:
            # game setup
            f = Fight(random.randint(15, 35))
            p1, p2 = get_players(game_players)
            f.add_players([p1, p2])

            # play game
            winner = f.fight()
            with lock:
                total_games_played.value += 1

            # evaluate winner
            if winner is not None:
                games_won[winner[0]] += 1

                # count consecutive wins
                if last_winner == winner[0]:
                    consecutive_wins += 1
                else:
                    consecutive_wins = 0
                last_winner = winner[0]
            
            # count games played up
            games_played[p1.name] += 1
            games_played[p2.name] += 1

            games_count += 1
            # check if next games can be skipped because of consecutive wins
            if consecutive_wins == consec_wins_before_skip:
                with lock:
                    total_games_skipped.value += games_per_matchup - games_count
                break
    print(f'worker finished with following matchups: {matchups}' + ' '*30)
Exemplo n.º 22
0
    def main(self):
        frostmourne = Weapon('Sword', 400, 0.8)
        gorehowl = Weapon('Axe', 400, 0.3)
        hero = Hero('Arthas', 10000, 'Lich King')
        orc = Orc('Hellscream', 12000, 1.5)
        hero.equip_weapon(frostmourne)
        orc.equip_weapon(gorehowl)
        self.set_player('player_1', hero)
        self.set_player('player_2', orc)
        self.set_player_position(self.player_1, [50, 50])
        self.set_player_position(self.player_2, [350, 350])
        winner = 'no one'
        myfont = pygame.font.SysFont("monospace", 20)
        clock = pygame.time.Clock()
        while True:
            self.screen.fill((100, 0, 0))
            self.draw_players()
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == KEYDOWN:
                    self.move_players(event.key)
            if colide(self.player_1.position, self.player_2.position):
                fight = Fight(self.player_1.entity, self.player_2.entity)
                winner = fight.simulate_fight()
                break

            self.draw_players()
            pygame.display.update()
            clock.tick(30)

        while True:
            self.screen.fill((100, 0, 0))
            pygame.display.update()
            print_text = myfont.render(winner, 1, (0, 100, 0))
            self.screen.blit(print_text, (50, 50))
            pygame.display.update()
            clock.tick(30)
Exemplo n.º 23
0
    def move_hero(self, direction):
        direction = direction.lower()

        x = self.hero_position_X
        y = self.hero_position_Y

        if direction == 'up':
            x -= 1
        if direction == 'down':
            x += 1
        if direction == 'left':
            y -= 1
        if direction == 'right':
            y += 1

        if x in range(0, self.X) and y in range(0, self.Y):
            enemy = Enemy(self.level * 15, self.level * 10)
            fight = Fight(self.hero, enemy, self.tmp_map, self.X, self.Y)
            if self.tmp_map[x][y] != '#':
                self.hero.take_mana()
                if self.tmp_map[x][y] == 'T':
                    self.treasure_found()
                if self.tmp_map[x][y] == 'E':
                    enemy = Enemy(self.level * 15, self.level * 10)
                    fight.fight()
                self._update_tmp_map(x, y)
                if self.hero.can_cast():
                    fight.remote_battle(x, y)
                return True
        else:
            print('Invalid. Your move was out of the map!')

        return False
Exemplo n.º 24
0
 def start(self):
     old_players = {}  # an string-Player dict
     result = {}
     for row in self.candidates:
         new_player = Player(row['Name'], int(row['Health']),
                             int(row['Damage']), int(row['Attacks']))
         for pname in old_players:
             f = Fight(old_players[pname], new_player)
             winner = f.fight()
             print '\n##########################################\n'
             # sleep(1)
             if result.has_key(winner):
                 result[winner] += 1
             else:
                 result[winner] = 1
         # add new player to the old player list
         old_players[row['Name']] = new_player
     result = sorted(result.items(),
                     key=operator.itemgetter(1),
                     reverse=True)
     print 'Number of winnings: ' + str(result)
     print 'Final winner is ' + result[0][0]
    def test_who_is_first(self):
        first = []
        for i in range(10):
            self.fight = Fight(self.hero, self.orc)
            first.append(self.fight.first)

        flag = [False, False]
        for i in first:
            if isinstance(i, Hero):
                flag[0] = True
            elif isinstance(i, Orc):
                flag[1] = True

        self.assertEqual(flag, [True, True])
class TestFight(unittest.TestCase):

    def setUp(self):
        self.pudge = Hero()
        self.magic = Spell(mana_cost=5, damage=33)
        self.sword = Weapon(damage=30)
        self.pudge.learn(self.magic)
        self.pudge.equip(self.sword)
        self.battle = Fight(self.pudge, (4, 6), (4, 5), 'walk')

    def test_direct_and_dist(self):
        direct_and_dist = self.battle.find_direct_and_dist()
        self.assertEqual(direct_and_dist[0], 'right')
        self.assertEqual(direct_and_dist[1], 1)

    def test_is_spell_more_eq_dmg(self):
        self.assertTrue(self.battle.is_spell_more_eq_dmg())

    def test_fight_scenario(self):
        self.assertTrue(self.battle.fight_scenario())
        print (self.battle)

    def test_combat_logg(self):
        pass
Exemplo n.º 27
0
    def challenge(self: 'Fighter', my_skill: str, opponent: 'Fighter'):
        """
        This class is used for a fighter to challenge another fighter.
        Different statements will be executed depending on the opponents status.
        For example if the opponent is a fighter the fight will happen immediately.
        If not the fight will be passed into list.

        :param my_skill: The skill that the player is challenging the opponent
        :param opponent: The Fighter to challenge.
        """
        from Fight import Fight
        from Warrior import Warrior
        from KnightErrant import KnightErrant
        if self.wealth == 0 or opponent.wealth == 0:
            print("Wealth is needed to start a challenge")
            return
        if isinstance(self, KnightErrant):
            if self.traveling:
                print("Cannot challenge while traveling")
                return
        if my_skill not in self.skills.keys():
            print(my_skill)
            print(self.skills.keys())
            print("Invalid skill")
            return
        if self == opponent:
            print("You cannot fight yourself")
        if isinstance(opponent, KnightErrant):
            # print("Opponent is a KnightErrant")
            opponent.challenge_request(self, my_skill)
            print(self.name + " Challenges " + opponent.name +
                  " Pending decision")
            #    if isinstance(self, Fighter):
        #        self.challenge_dict[opponent] = False
        if isinstance(opponent, Warrior):
            if not isinstance(opponent, KnightErrant):
                # print("Opponent is a warrior")
                opponent.challenge_request(self, my_skill)
                print(self.name + " Challenges " + opponent.name +
                      " Pending decision")
        #        if isinstance(self, Fighter):
        #            self.challenge_dict[opponent] = False
        else:
            print(self.name + " Challenges " + opponent.name)
            print(self.name + " is a " + self.__class__.__name__ + " and " +
                  opponent.name + " is a " + opponent.__class__.__name__)
            fight1 = Fight(self, opponent, my_skill)
            print("Winner:" + fight1.winner)
Exemplo n.º 28
0
 def hero_atack(self,by):
     if by == "spell":
         top_border = False
         bot_border = False
         left_border = False
         right_border = False
         if self._hero is None or self._hero.spell is None:
             return False
         for rng in range(0, self._hero.spell.cast_range + 1):
             top_border = self._hero._y == 0
             if not top_border:
                 if self._map[self._hero._y - rng][self._hero._x] == "E" and self._hero.can_cast():
                     enemy = self._enemies.pop()
                     f = Fight(self._hero, enemy)
                     if f.start_battle(self._hero, enemy):
                         self._map[enemy._y][enemy._x] = "."
                         return True
             bot_border = self._hero._y == len(self._map)
             if not bot_border:
                 if self._map[self._hero._y + rng][self._hero._x] == "E" and self._hero.can_cast():
                     enemy = self._enemies.pop()
                     f = Fight(self._hero, enemy)
                     print(enemy._x, enemy._y)
                     if f.start_battle(self._hero, enemy):
                         self._map[enemy._y][enemy._x] = "."
                         return True
             left_border = self._hero._x == 0
             if not left_border:
                 if self._map[self._hero._y][self._hero._x - rng] == "E" and self._hero.can_cast():
                     enemy = self._enemies.pop()
                     f = Fight(self._hero, enemy)
                     if f.start_battle(self._hero, enemy):
                         self._map[enemy._y][enemy._x] = "."
                         return True
             right_border = self._hero._x == 0
             if not right_border:
                 if self._map[self._hero._y][self._hero._x + rng] == "E" and self._hero.can_cast():
                     enemy = self._enemies.pop()
                     f = Fight(self._hero, enemy)
                     if f.start_battle(self._hero, enemy):
                         self._map[enemy._y][enemy._x] = "."
                         return True
     return False
Exemplo n.º 29
0
 def accept_random(self):
     """
     This function is used to accept a random challenge stored in the list
     """
     from Fight import Fight
     from KnightErrant import KnightErrant
     if isinstance(self, KnightErrant):
         if self.traveling:
             print("Knight is traveling cannot accept challenge")
             return
     select = random.randrange(len(self.fight_list))
     request = self.fight_list.pop(select)
     item = self.fight_item.pop(select)
     print(self.name + " is a " + self.__class__.__name__ + " and " +
           request.name + " is a " + request.__class__.__name__)
     print(self.name + " accepted " + request.name + "'s challenge")
     fight2 = Fight(self, request, item)
     print("Winner:" + fight2.winner)
Exemplo n.º 30
0
 def accept_first(self):
     """
     This function is used to accept the first challenge stored in the list
     """
     from Fight import Fight
     from KnightErrant import KnightErrant
     if isinstance(self, KnightErrant):
         if self.traveling:
             print("Knight is traveling cannot accept challenge")
             return
     request = self.fight_list.pop()
     item = self.fight_item.pop()
     print(self.name + " is a " + self.__class__.__name__ + " and " +
           request.name + " is a " + request.__class__.__name__)
     # First case if its a fighter we have to check if withdrawal is allowed
     # if not request.challenge_dict[self]:
     print(self.name + " accepted " + request.name + "'s challenge")
     fight2 = Fight(self, request, item)
     print("Winner:" + fight2.winner)
Exemplo n.º 31
0
        def while_cast_range(cast_range, expr_y, expr_x, direction):
            x = self.hero.coord_X
            y = self.hero.coord_Y

            i = 0
            while i <= cast_range:
                temp_y = eval(expr_y)
                temp_x = eval(expr_x)
                if temp_x >= 0 and temp_x < len(
                        self.map[0]) and temp_y >= 0 and temp_y < len(
                            self.map):
                    if self.map[temp_y][temp_x] == '#':
                        return False
                    if self.map[temp_y][temp_x] == 'E':
                        if Fight().fight_simulator(hero=self.hero,
                                                   enemy=random_enemy,
                                                   attack_range=i,
                                                   direction=direction):
                            return (temp_y, temp_x)
                else:
                    return False
                i += 1
            return False
Exemplo n.º 32
0
class MyGame(arcade.Window):
    def __init__(self, width, height, title):
        super().__init__(width, height, title)

        self.dungeon = None
        self.hero = None

        self.left_pressed = False
        self.right_pressed = False
        self.up_pressed = False
        self.down_pressed = False
        self.move_char = (".", [0, 0])
        self.fight = Fight()
        arcade.set_background_color((59, 68, 75))

    def setup(self):
        self.dungeon = Dungeon("map.txt")
        self.hero = Hero("Geralt", "white wolf", 150, 150, 5)
        self.hero.equip(Weapon("Sword", 30))
        self.hero.learn(Spell("wolf's attack", 20, 20, 2))
        self.dungeon.spawn(self.hero)
        self.command = None

    def on_draw(self):
        arcade.start_render()

        x = self.dungeon.borders[1] * 20 + LEFT_MARGIN - 20
        y = 260
        arcade.draw_rectangle_filled(x, y, 410, 410, (135, 169, 107))
        arcade.draw_rectangle_outline(x, y, 420, 420, (105, 53, 156), 10)
        arcade.draw_text("To move pres the keybord arrows.\nTo attack first you should choose\ndirection. Press on of the keys:\n 'u' for up, 'd' for down,\n 'l' for left, 'r' for right\n......................................",\
            x - 200, y + 100, (55, 3, 106), 14)

        # Prints the map
        for row in range(self.dungeon.borders[0]):
            # Loop for each column
            for column in range(self.dungeon.borders[1]):
                # Calculate our location
                x = column * COLUMN_SPACING + LEFT_MARGIN
                y = (self.dungeon.borders[0] - row -
                     1) * ROW_SPACING + BOTTOM_MARGIN

                # Draw the item
                if (self.dungeon.matrix[row][column] == "#"):
                    arcade.draw_rectangle_filled(x, y, 30, 30, (191, 79, 81))
                elif (self.dungeon.matrix[row][column] == "-"):
                    if row == 0 or row == self.dungeon.borders[0] - 1:
                        if column == 0 or column == self.dungeon.borders[1] - 1:
                            arcade.draw_rectangle_filled(
                                x, y, 30, 30, (59, 68, 75))
                        else:
                            arcade.draw_rectangle_filled(
                                x, y, 50, 30, (59, 68, 75))
                    if column == 0 or column == self.dungeon.borders[1] - 1:
                        if row == 0 or row == self.dungeon.borders[0] - 1:
                            arcade.draw_rectangle_filled(
                                x, y, 30, 30, (59, 68, 75))
                        else:
                            arcade.draw_rectangle_filled(
                                x, y, 30, 50, (59, 68, 75))
                elif (self.dungeon.matrix[row][column] == "H"):
                    arcade.draw_rectangle_filled(x, y, 30, 30, (79, 134, 247))
                    arcade.draw_text("H", x - 10, y - 20, arcade.color.BLUE,
                                     28)
                elif (self.dungeon.matrix[row][column] == "E"):
                    arcade.draw_rectangle_filled(x, y, 30, 30, (255, 117, 24))
                    arcade.draw_text("E", x - 10, y - 20, arcade.color.RED, 28)
                elif (self.dungeon.matrix[row][column] == "T"):
                    arcade.draw_rectangle_filled(x, y, 30, 30, (150, 120, 182))
                    arcade.draw_text("T", x - 10, y - 20, (55, 3, 106), 28)
                elif (self.dungeon.matrix[row][column] == "G"):
                    arcade.draw_rectangle_filled(x, y, 30, 30, (153, 230, 179))
                    arcade.draw_text("G", x - 10, y - 20, (0, 130, 127), 28)
                else:
                    arcade.draw_rectangle_filled(x, y, 30, 30, (135, 169, 107))

        x = self.dungeon.borders[1] * 20 + LEFT_MARGIN - 20
        y = self.dungeon.borders[1] * 10 + BOTTOM_MARGIN
        arcade.draw_rectangle_outline(x, y, 420, 220, (105, 53, 156), 10)

    def on_update(self, delta_time):
        """
        if self.up_pressed and not self.down_pressed:
            self.dungeon.move_hero("up")
        elif self.down_pressed and not self.up_pressed:
            self.dungeon.move_hero("down")
        if self.left_pressed and not self.right_pressed:
            self.dungeon.move_hero("left")
        elif self.right_pressed and not self.left_pressed:
            self.dungeon.move_hero("left")
        """

    def on_key_press(self, key, modifiers):
        """Called whenever a key is pressed. """

        if key == arcade.key.UP:

            self.move_char = self.dungeon.move_hero("up")
            print("HERREEEEERERERER")  #, self.move_hero)

            self.check_move()
            #self.up_pressed = True
        elif key == arcade.key.DOWN:

            self.move_char = self.dungeon.move_hero("down")
            self.check_move()
            #self.down_pressed = True
        elif key == arcade.key.LEFT:

            self.move_char = self.dungeon.move_hero("left")
            self.check_move()
            # self.left_pressed = True
        elif key == arcade.key.RIGHT:

            self.move_char = self.dungeon.move_hero("right")
            self.check_move()
            # self.right_pressed = True

        elif key == arcade.key.NUM_1 or key == arcade.key.KEY_1:
            self.command = self.fight.get_hero_command(1)

        elif key == arcade.key.NUM_2 or key == arcade.key.KEY_2:
            print('hhhhhhh')
            self.command = self.fight.get_hero_command(2)
            print(self.command)

        elif key == arcade.key.NUM_3 or key == arcade.key.KEY_3:
            self.command = self.fight.get_hero_command(3)

        elif key == arcade.key.NUM_4 or key == arcade.key.KEY_4:
            self.command = self.fight.get_hero_command(4)

    def on_key_release(self, key, modifiers):
        """Called when the user releases a key. """

        if key == arcade.key.UP:
            self.up_pressed = False
        elif key == arcade.key.DOWN:
            self.down_pressed = False
        elif key == arcade.key.LEFT:
            self.left_pressed = False
        elif key == arcade.key.RIGHT:
            self.right_pressed = False

    def check_move(self):
        print("nznznz", self.move_char)
        if self.move_char[0] == "E":
            print("WTF???")
            #fight = Fight()
            self.dungeon.hero = self.battle(1)
            if self.dungeon.hero.is_alive():
                self.dungeon.change_map(".")
                self.dungeon.hero_place[self.move_char[1]] = self.move_char[2]
                self.dungeon.change_map("H")
        else:
            return "Hero made move."

    def battle(self, distance):
        enemy = self.dungeon.enemies.pop()
        self.fight.start_fight(self.dungeon.hero, enemy, distance)
        while self.dungeon.hero.is_alive() and enemy.is_alive():
            # the desition of the player
            # self.fight.distance = distance
            if self.dungeon.hero.is_alive():
                print(self.command)
                if self.command is not None:

                    if enemy.is_alive():
                        print(self.fight.hero_attack())
                        if not enemy.is_alive():
                            print("Enemy is dead.")
                if self.enemy.is_alive():
                    if self.hero.is_alive():
                        print(self.fight.enemy_attack())
                        if not self.dungeon.hero.is_alive():
                            print("Hero is dead")
        return self.hero
Exemplo n.º 33
0
    def hero_atack(self):
        enemy = Enemy(health=random.randrange(50, 150),
                      mana=random.randrange(20, 100),
                      damage=random.randrange(20, 80))

        # finding the enemy
        distance = 0
        curr_vec = 1
        row = self.__hero_pos[0]
        col = self.__hero_pos[1]
        choices = []
        range_to_enemy = 0
        atack_range = self.__hero.get_cast_range()

        if atack_range:
            while row - curr_vec >= 0 and curr_vec <= atack_range:
                if self.__map[row - curr_vec][col] == '#':
                    break
                choices.append((row - curr_vec, col))
                curr_vec -= 1

            curr_vec = 1
            while col + curr_vec < self.__cols and curr_vec <= atack_range:
                if self.__map[row][col + curr_vec] == '#':
                    break
                choices.append((row, col + curr_vec))
                curr_vec += 1

            curr_vec = 1
            while row + curr_vec < self.__rows and curr_vec <= atack_range:
                if self.__map[row + curr_vec][col] == '#':
                    break

                choices.append((row + curr_vec, col))
                curr_vec += 1

            curr_vec = 1
            while col - \
                    curr_vec >= 0 and curr_vec <= atack_range and self.__map[row][col - curr_vec] != '#':
                if self.__map[row][col - curr_vec] == '#':
                    break

                choices.append(row, col + curr_vec)
                curr_vec -= 1
        fight = Fight(self.__hero, enemy)
        fight_pos = 0
        for elem in choices:
            if self.__map[elem[0]][elem[1]] == 'E':
                fight_pos = elem

        if fight_pos != 0:
            range_to_enemy = max(row - fight_pos[0], col - fight_pos[1])

        for i in range(range_to_enemy):
            fight.moving_fight()

        result = fight.static_fight()
        if result:
            print("Hero wins")
            self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
            return True
        else:
            print("Hero is dead! Respawning...")
            self.spawn(self.__hero)
            return True
Exemplo n.º 34
0
 def move_hero(self, direction):
     if direction not in ["up", "down", "left", "right"]:
         raise ValueError
     if direction == "right":
         if self._hero._x == len(self._map[0]) - 1:
             return False
         if self._map[self._hero._y][self._hero._x + 1] == "#":
             return False
         if self._map[self._hero._y][self._hero._x + 1] == "E":
             f = Fight(self._hero, self._enemies.pop())
             f.start_battle(self._hero, self._enemies.pop())
         self._map[self._hero._y][self._hero._x] = "."
         self._hero._x += 1
         self._map[self._hero._y][self._hero._x] = "H"
         return True
     if direction == "left":
         if self._hero._x == 0:
             return False
         if self._map[self._hero._y][self._hero._ - 1] == "#":
             return False
         if self._map[self._hero._y][self._hero._x - 1] == "E":
             f = Fight(self._hero, self._enemies.pop())
             f.start_battle(self._hero, self._enemies.pop())
         self._map[self._hero._y][self._hero._x] = "."
         self._hero._x -= 1
         self._map[self._hero._y][self._hero._x] = "H"
         return True
     if direction == "up":
         if self._hero._y == 0:
             return False
         if self._map[self._hero._y - 1][self._hero._x] == "#":
             return False
         if self._map[self._hero._y - 1][self._hero._x] == "E":
             f = Fight(self._hero, self._enemies.pop())
             f.start_battle(self._hero, self._enemies.pop())
         self._map[self._hero._y][self._hero._x] = "."
         self._hero._y -= 1
         self._map[self._hero._y][self._hero._x] = "H"
         return True
     if direction == "down":
         if self._hero._y == len(self._map) - 1:
             return False
         if self._map[self._hero._y + 1][self._hero._x] == "#":
             return False
         if self._map[self._hero._y + 1][self._hero._x] == "E":
             f = Fight(self._hero, self._enemies.pop())
             f.start_battle(self._hero, self._enemies.pop())
         self._map[self._hero._y][self._hero._x] = "."
         self._hero._y += 1
         self._map[self._hero._y][self._hero._x] = "H"
         return True
Exemplo n.º 35
0
    def __movement(self, new_hero_pos):
        if self.__map[new_hero_pos[0]][new_hero_pos[1]] in ['#', 'T', 'E']:
            if self.__map[new_hero_pos[0]][new_hero_pos[1]] == '#':
                return False

            if self.__map[new_hero_pos[0]][new_hero_pos[1]] == 'T':
                self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
                self.__hero_pos = new_hero_pos

                treasure = self.spawn_treasure()
                if isinstance(treasure, ManaPotion):
                    print("Mana pot found")
                    mana = treasure.get_mana()
                    self.__hero.take_mana(mana)
                    print("Hero healed with {} mana".format(mana))
                    print("Hero's mana is: {}".format(self.__hero.get_mana()))

                if isinstance(treasure, HealthPotion):
                    print("Healing pot found!")
                    health = treasure.get_health()
                    self.__hero.take_healing(health)
                    print("Hero healed with {} health".format(health))
                    print(
                        "Hero;s health is: {}".format(
                            self.__hero.get_health()))

                if isinstance(treasure, Weapon):
                    print("Weapon found!")
                    self.__hero.equip(treasure)

                if isinstance(treasure, Spell):
                    print("Spell found!")
                    self.__hero.learn(treasure)

                self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
                return True

            if self.__map[new_hero_pos[0]][new_hero_pos[1]] == 'E':
                print("Enemy found")
                self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
                self.__hero_pos = new_hero_pos

                # enemy spawner
                enemy = Enemy(health=random.randrange(50, 150),
                              mana=random.randrange(20, 100),
                              damage=random.randrange(20, 80))

                # initiate fight
                fight = Fight(self.__hero, enemy)
                result = fight.static_fight()
                if result:
                    print("Hero wins")
                    self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
                    return True
                else:
                    print("Hero is dead! Respawning...")
                    self.spawn(self.__hero)
                    return False
            return True
        else:
            self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
            self.__hero_pos = new_hero_pos
            self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
            return True
 def start_fight(self, fight_type):
     print("You Started a Fight with an Enemy")
     battle = Fight(self.hero, self.hero_position, self.enemy_position, fight_type)
     battle.fight_scenario()
 def test_simulate_fight_Hero_Wins(self):
     self.orc = Orc('Gul Dan', 500, 1)
     self.fight = Fight(self.hero, self.orc)
     self.assertEqual(self.fight.simulate_fight(), 'hero wins')
Exemplo n.º 38
0
from AryaStark import AryaStark
from JaimeLannister import JaimeLannister
from JohnSnow import JohnSnow
from TyrionLannister import TyrionLannister
from Fight import Fight


def select_fighter(fighters: list):
    while True:
        name = input("Please enter a fighter name\n")
        for fighter in fighters:
            if name.lower() in fighter.name.lower():
                return fighter

        print("This fighter does not exist")


if __name__ == "__main__":
    fighters = [AryaStark(), JohnSnow(), TyrionLannister(), JaimeLannister()]
    fighter1 = select_fighter(fighters)
    fighter2 = select_fighter(fighters)

    fight = Fight(fighter1, fighter2)
    fight.start()
Exemplo n.º 39
0
from random import randint
from Monstros import Monstros
from Status import Status
from Torneio import Torneio
from Fight import Fight
from Jsonarchive import Jsonarchive
import Decode

import json

data_json = Decode.Decode.decode("champions.json")

part = []

for n in range(0, Decode.Decode.count_monster):

    monster = Monstros(data_json[0][n], data_json[1][n], data_json[2][n],
                       data_json[3][n], data_json[4][n], data_json[5][n],
                       data_json[6][n])
    part.append(monster)

Fight.fight(part)

Fight.fight(Monstros.quartas)

Fight.fight(Monstros.semif)

Fight.fight(Monstros.final)
 def test_simulate_fight_Orc_Wins(self):
     self.hero = Hero('Tirion', 500, 'The AshBringer')
     self.fight = Fight(self.hero, self.orc)
     self.assertEqual(self.fight.simulate_fight(), 'orc wins')
Exemplo n.º 41
0
class Forest(Frame):
    def __init__(self):
        self.cord = [
            [0, 3],
            [1, 3],
            [2, 3],
            [3, 3],
            [4, 3],
            [0, 2],
            [1, 2],
            [2, 2],
            [3, 2],
            [4, 2],
            [0, 1],
            [1, 1],
            [2, 1],
            [3, 1],
            [4, 1],
            [0, 0],
            [1, 0],
            [2, 0],
            [3, 0],
            [4, 0],
        ]
        self.events = [
            0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4
        ]
        random.shuffle(self.events)
        self.pos = [0, 0]
        self.x = 100
        self.y = 400

    def gup(self, player):
        self.root.destroy()
        self.does(player, Enemy(player.level))
        self.pos[1] += 1
        self.x = self.pos[0] * 100 + 100
        self.y = 400 - self.pos[1] * 100

        self.move(player, 1)

    def gdown(self, player):
        self.root.destroy()
        self.does(player, Enemy(player.level))
        self.pos[1] -= 1
        self.x = self.pos[0] * 100 + 100
        self.y = 400 - self.pos[1] * 100
        self.move(player, 1)

    def gright(self, player):
        self.root.destroy()
        self.does(player, Enemy(player.level))
        self.pos[0] += 1
        self.x = self.pos[0] * 100 + 100
        self.y = 400 - self.pos[1] * 100
        self.move(player, 1)

    def gleft(self, player):
        self.root.destroy()
        self.does(player, Enemy(player.level))
        self.pos[0] -= 1
        self.x = self.pos[0] * 100 + 100
        self.y = 400 - self.pos[1] * 100
        self.move(player, 1)

    def move(self, player, t):
        if t == 0:
            self.pos = [0, 0]
            self.x = 100
            self.y = 400

        self.root = tk.Tk()
        self.root.geometry("600x500")
        self.frame = tk.Frame(self.root, bg='#80c1ff', bd=5)
        self.frame.place(relx=0, rely=0, width=700, height=900)
        canvas = tk.Canvas(self.frame, width=700, height=900, bg='#80c1ff')
        canvas.create_line(100, 100, 100, 400, fill='blue', width=5)
        canvas.create_line(200, 100, 200, 400, fill='blue', width=5)
        canvas.create_line(300, 100, 300, 400, fill='blue', width=5)
        canvas.create_line(400, 100, 400, 400, fill='blue', width=5)
        canvas.create_line(500, 100, 500, 400, fill='blue', width=5)
        canvas.create_line(100, 100, 500, 100, fill='blue', width=5)
        canvas.create_line(100, 200, 500, 200, fill='blue', width=5)
        canvas.create_line(100, 300, 500, 300, fill='blue', width=5)
        canvas.create_line(100, 400, 500, 400, fill='blue', width=5)
        canvas.create_line(100, 500, 500, 500, fill='blue', width=5)
        canvas.create_rectangle(self.x - 5,
                                self.y - 5,
                                self.x + 5,
                                self.y + 5,
                                fill='red')
        canvas.pack()
        button = tk.Button(self.frame,
                           text="leave",
                           command=lambda: self.leave(player))
        button.place(relx=0, rely=0, relwidth=.07, relheight=.05)
        for i in range(len(self.cord)):
            if self.pos[0] == self.cord[i][0]:
                if self.pos[1] + 1 == self.cord[i][1]:
                    self.up = tk.Button(self.frame,
                                        text="up",
                                        command=lambda: self.gup(player))
                    self.up.place(relx=0, rely=.1, relwidth=.07, relheight=.05)
            if self.pos[0] == self.cord[i][0]:
                if self.pos[1] - 1 == self.cord[i][1]:
                    self.down = tk.Button(self.frame,
                                          text="down",
                                          command=lambda: self.gdown(player))
                    self.down.place(relx=0,
                                    rely=.2,
                                    relwidth=.07,
                                    relheight=.05)
            if self.pos[0] + 1 == self.cord[i][0]:
                if self.pos[1] == self.cord[i][1]:
                    self.right = tk.Button(self.frame,
                                           text="right",
                                           command=lambda: self.gright(player))
                    self.right.place(relx=0,
                                     rely=.3,
                                     relwidth=.07,
                                     relheight=.05)
            if self.pos[0] - 1 == self.cord[i][0]:
                if self.pos[1] == self.cord[i][1]:
                    self.left = tk.Button(self.frame,
                                          text="left",
                                          command=lambda: self.gleft(player))
                    self.left.place(relx=0,
                                    rely=.4,
                                    relwidth=.07,
                                    relheight=.05)

        self.root.mainloop()

    def battle(self, player, enemy):
        self.fight = Fight()
        self.fight.start(player, enemy)
        return

    def leave(self, player):
        player.health = player.set
        self.root.destroy()

    def does(self, player, enemy):
        for i in range(len(self.cord)):
            if self.pos == self.cord[i]:
                if self.events[i] < 2:
                    self.battle(player, enemy)
                    break
        return
Exemplo n.º 42
0
 def test_fight_init(self):
     hero = Hero("Natsu", 10000, "DragonSlayer")
     orc = Orc("BadOrc", 100, 2)
     fight = Fight(hero, orc)
     self.assertEqual(fight.hero, hero)
     self.assertEqual(fight.orc, orc)
Exemplo n.º 43
0
class Dungeon:
    def __init__(self, text_file , lootListPath):
        self.matrix = []
        with open(str(text_file)) as f:
            self.matrix = f.readlines()
        self.matrix = [x.strip() for x in self.matrix]
        self.hero = None
        self.fight = Fight()
        self.borders = [len(self.matrix), len(self.matrix[0])]
        self.hero_place = []
        self.end_of_game = False
        enemy = Enemy(100, 120, 20)
        enemy.equip(Weapon("Sword", 40))
        enemy.learn(Spell("Fire", 30, 20, 3))
        self.enemies = [enemy, Enemy(70, 70, 15), Enemy(50, 50, 10)]
        self.treasure = [Weapon("Axe", 35), Spell("FireStorm", 40, 20, 3), ["h", 20], ["h", 30]]

        self.loot_dict = self.__class__.extract_loot_dictionary(lootListPath)

    @classmethod
    def extract_loot_dictionary(cls, filePath):
        with open(filePath, 'r') as f:
            loot_dict = json.load(f)
        return loot_dict

    def print_map(self):
        for line in self.matrix:
            print(line)

    def get_start(self):
        for i in range(len(self.matrix)):
            if 'S' in self.matrix[i]:
                return [i, self.matrix[i].index('S')]
        return [0, 0]

    def get_end(self):
        for i in range(len(self.matrix)):
            if 'G' in self.matrix[i]:
                return [i, self.matrix[i].index('G')]
        return [0, 0]

    def spawn(self, hero):
        self.hero = hero
        if hero.is_alive():
            self.hero_place = self.get_start()
            self.change_map("H")
        else:
            print('End')

    def change_map(self, ch):
        s = list(self.matrix[self.hero_place[0]])
        s[self.hero_place[1]] = ch
        self.matrix[self.hero_place[0]] = "".join(s)

    def get_treasure(self):
        treasure = random.choice(self.treasure)
        if type(treasure) is list:
            self.hero.take_healing(treasure[1])
            print("hero health is", self.hero.get_health())
        elif type(treasure) is Spell:
            self.hero.learn(treasure)
            print("hero learned", treasure.name)
        else:
            self.hero.equip(treasure)
            print("hero found", treasure.name)
        print()

    def move_hero(self, direction):
        directions_vertical = {'up': -1, 'down': 1}
        directions_horisontal = {'left': -1, 'right': 1}
        if direction in directions_vertical.keys():
            next_point = self.hero_place[0] + directions_vertical[direction]
            if next_point > 0 or next_point < self.borders[0]:
                if self.matrix[next_point][self.hero_place[1]] == "#":
                    return False
                if self.matrix[next_point][self.hero_place[1]] == "-":
                    return False
                elif self.matrix[next_point][self.hero_place[1]] == "E":
                    self.hero_atack(direction)
                    self.change_map(".")
                    self.hero_place[0] = next_point
                    self.change_map("H")
                elif self.matrix[next_point][self.hero_place[1]] == "T":
                    self.change_map(".")
                    self.hero_place[0] = next_point
                    self.change_map("H")
                    self.get_treasure()
                    # add treasure
                    # print("Found treasure!")
                elif self.matrix[next_point][self.hero_place[1]] == ".":
                    self.change_map(".")
                    self.hero_place[0] = next_point
                    self.change_map("H")
                else:
                    print("End of the game!")
                    print("You won!!!")
            else:
                return False
        if direction in directions_horisontal.keys():
            next_point = self.hero_place[1] + directions_horisontal[direction]
            if next_point > 0 or next_point < self.borders[1]:
                if self.matrix[self.hero_place[0]][next_point] == "#":
                    return False
                if self.matrix[self.hero_place[0]][next_point] == "-":
                    return False
                elif self.matrix[self.hero_place[0]][next_point] == "E":
                    self.hero_atack(direction)
                    self.change_map(".")
                    self.hero_place[1] = next_point
                    self.change_map("H")
                elif self.matrix[self.hero_place[0]][next_point] == "T":
                    self.change_map(".")
                    self.hero_place[1] = next_point
                    self.change_map("H")
                    # add treasure
                    print("Found treasure!")
                elif self.matrix[self.hero_place[0]][next_point] == ".":
                    self.change_map(".")
                    self.hero_place[1] = next_point
                    self.change_map("H")
                else:
                    self.end_of_game = True
                    print("End of the game!")
                    print("You won!!!")
            else:
                return False
        return False

    def hero_atack(self, direction):
        distance = self.check_for_enemy(direction)
        if distance == 0:
            print("There is no enemy in hero's ramge")
        else:
            enemy = self.enemies.pop()
            self.hero = self.fight.start_fight(self.hero, enemy, distance)
            if not self.hero.is_alive():
                self.end_of_game = True
            # else:
            #    s = list(self.matrix[coord[0]])
            #    s[coord[1]] = "."
            #    self.matrix[self.hero_place[0]] = "".join(s)

    def check_for_enemy(self, direction):
        directions_vertical = {'up': -1, 'down': 1}
        directions_horisontal = {'left': -1, 'right': 1}
        spell_range = self.hero.spell.cast_range
        coord = self.hero_place
        distance = 0

        if direction in directions_vertical.keys():
            for i in range(spell_range + 1):
                index = self.hero_place[0] + i * directions_vertical[direction]
                if index <= 0 or index >= self.borders[1] - 1:
                    break
                if self.matrix[index][self.hero_place[1]] == "#":
                    distance = 0
                    break
                elif self.matrix[index][self.hero_place[1]] == "E":
                    coord = [index, self.hero_place[1]]
                    
                    ############

                    s = list(self.matrix[index])
                    s[hero_place[1]] == "."
                    self.matrix[index] = "".join(s)


                    break
                else:
                    distance += 1
            return [distance, coord]
        if direction in directions_horisontal.keys():
            for i in range(spell_range + 1):
                index = self.hero_place[1] + i * directions_horisontal[direction]
                if index <= 0 or index >= self.borders[1] - 1:
                    break
                if self.matrix[self.hero_place[0]][index] == "#":
                    return 0
                elif self.matrix[self.hero_place[0]][index] == "E":
                    coord = [self.hero_place[1], index]
                    
                    #############

                    s = list(self.matrix[self.hero_place[0]])
                    s[index] = "."
                    self.matrix[self.hero_place[0]] = "".join(s)

                    return [distance, coord]
                else:
                    distance += 1
        return [0, coord]

    def remove_enemy(self, direction):
        directions_vertical = {'up': -1, 'down': 1}
        directions_horisontal = {'left': -1, 'right': 1}
        spell_range = self.hero.spell.cast_range

        distance = 0

        if direction in directions_vertical.keys():
            for i in range(spell_range + 1):
                index = self.hero_place[0] + i * directions_vertical[direction]
                if index <= 0 or index >= self.borders[1] - 1:
                    break
                if self.matrix[index][self.hero_place[1]] == "#":
                    distance = 0
                    break
                elif self.matrix[index][self.hero_place[1]] == "E":
                    break
                else:
                    distance += 1
            return distance
        if direction in directions_horisontal.keys():
            for i in range(spell_range + 1):
                index = self.hero_place[1] + i * directions_horisontal[direction]
                if index <= 0 or index >= self.borders[1] - 1:
                    break
                if self.matrix[self.hero_place[0]][index] == "#":
                    return 0
                elif self.matrix[self.hero_place[0]][index] == "E":
                    return distance
                else:
                    distance += 1
        return 0
Exemplo n.º 44
0
 game = Game()
 map_list, map_x_axis_size, map_y_axis_size = game.create_map(map_list, map_x_axis_size, map_y_axis_size,
                                                              map_elements_list)
 player = Player()
 print(player.health)
 player.create_player()
 game.place_player(map_list, player_position_x_axis, player_position_y_axis)
 game.print_out_map(map_list)
 game.reset_map(map_list, player_position_x_axis, player_position_y_axis)
 while game_is_on:
     player_position_x_axis, player_position_y_axis = game.ask_to_move_player(player_position_x_axis,
                                                                              player_position_y_axis,
                                                                              map_x_axis_size,
                                                                              map_y_axis_size)
     if game.check_for_enemy(map_list, player_position_x_axis, player_position_y_axis):
         fight = Fight()
         enemy = fight.create_enemies()
         while fight_is_on:
             if fight.action_player(enemy, player):
                 if fight.check_for_win(enemy):
                     break
                 fight.action_enemy(enemy, player)
                 if fight.check_for_loss(player):
                     game_is_on = False
                     break
             else:
                 break
     game.place_player(map_list, player_position_x_axis, player_position_y_axis)
     os.system('cls')
     game.print_out_map(map_list)
     game.reset_map(map_list, player_position_x_axis, player_position_y_axis)
Exemplo n.º 45
0
 def setUp(self):
     self.testOrc = Orc("TestOrc", 100, 1.4)
     self.testHero = Hero("TestHero", 100, "Tester")
     self.testOrc.weapon = Weapon("TestBrick", 30, 0.3)
     self.testHero.weapon = Weapon("TestOrcSlapper", 50, 0.6)
     self.testFight = Fight(self.testOrc, self.testHero)
Exemplo n.º 46
0
 def battle(self, player, enemy):
     self.fight = Fight()
     self.fight.start(player, enemy)
     return
Exemplo n.º 47
0
while(select_number):
    player_type = int(raw_input())
    print player_type
    if player_type >= 1 and player_type <= 3:
        select_number = False
    else:
        print "Please select one of the warrior type"


player = Player(player_name,player_type)
monster = Monster()

player.to_string()
monster.to_string()

fight = Fight(player, monster)
fight.autofight()






# location = Room('arena')
# player = Player(player_name, player_type)
# game = Engine(player, location)
# game.play()



# TODO