Ejemplo n.º 1
0
def get_game_variables(constants, kolors, current_roster, current_mm):
    fighter_component = Fighter(hp=30, protection=2, power=5)
    inventory_component = Inventory(26)
    player = Entity(0,
                    0,
                    '@',
                    tcod.black,
                    'Player',
                    blocks=True,
                    render_order=RenderOrder.ACTOR,
                    fighter=fighter_component,
                    inventory=inventory_component)
    entities = [player]

    map_type = 'Dungeon'  #Choices: Dungeon, Cave, World

    if map_type == 'Dungeon':
        indoors = True
        game_map = Dungeon(constants['map_width'], constants['map_height'])
        game_map.make_map(constants['max_rooms'], constants['room_min_size'],
                          constants['room_max_size'], constants['map_width'],
                          constants['map_height'], player, entities,
                          constants['max_monsters_per_room'],
                          constants['max_items_per_room'], kolors,
                          current_roster, current_mm)
    elif map_type == 'Cave':
        indoors = True
        game_map = Cave(constants['map_width'], constants['map_height'])
        game_map.make_cave(constants['map_width'], constants['map_height'],
                           player, entities,
                           constants['max_monsters_per_cave'],
                           constants['max_items_per_cave'], kolors,
                           current_roster, current_mm)
    elif map_type == 'World':
        indoors = False
        game_map = World(constants['map_width'], constants['map_height'])
        game_map.make_world(constants['map_width'], constants['map_height'],
                            player, entities,
                            constants['max_monsters_per_spawn'], kolors,
                            current_roster, current_mm)

    #Initialize the message log
    message_log = MessageLog(constants['message_x'],
                             constants['message_width'],
                             constants['message_height'])

    game_state = GameStates.PLAYERS_TURN

    return player, entities, game_map, indoors, message_log, game_state
Ejemplo n.º 2
0
 def setUp(self):
     self.hero = Hero("Bron", "Dragon", 100, 100, 2)
     self.dungeon = Dungeon("map2.txt")
     self.weapon = Weapon(name="The Axe of Destiny", damage=20)
     self.spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)
     self.mana_potion = self.hero.mana
     self.health_potion = self.hero.health
Ejemplo n.º 3
0
 def __init__(self, hero, enemy):
     self.hero = hero
     self.enemy = enemy
     self.dungeon = Dungeon("Treasure-Map")
Ejemplo n.º 4
0
class Fight:

    def __init__(self, hero, enemy):
        self.hero = hero
        self.enemy = enemy
        self.dungeon = Dungeon("Treasure-Map")

    def message_start_fight(self):
        return "A fight is started between our {} and {}".format(self.hero, self.enemy)

    def message_hero_cast(self):
        return "Hero casts a {}, hits enemy for {} dmg.Enemy health is {} \
        ".format(self.hero.get_spell().get_name(), self.hero.get_spell().get_damage(), self.enemy.get_health())

    def message_no_more_mana(self):
        return "Hero does not have mana for another {}.".format(self.hero.get_spell().get_name())

    def message_enemy_hit(self):
        return "Enemy hits hero with {}dmg. Hero health is {}".format(self.enemy.get_damage(), self.hero.get_health())

    def message_move_enemy(self):
        return "Enemy moves one square to the {} in order to get to the hero. This is his move.".format(self.dungeon.give_moved_direction())

    def message_use_weapon(self):
        return "Hero hits with {} for {} dmg. Enemy health is {}".format(self.hero.get_weapon().get_name(), self.hero.get_weapon().get_damage(), self.enemy.get_health())

    def message_dead(self, dead):
        return "{} is dead!".format(dead)

    def give_moved_direction(self):
        if self.dungeon.get_coords()[0] > self.dungeon.get_enemy_coords()[0]:
            return "up"
        if self.dungeon.get_coords()[0] < self.dungeon.get_enemy_coords()[0]:
            return "down"
        if self.dungeon.get_coords()[1] > self.dungeon.get_enemy_coords()[1]:
            return "right"
        else:
            return "left"

    def move_enemy(self, direction):
        if direction == "right":
            self.dungeon.get_enemy_coords()[1] += 1
            return
        if direction == "left":
            self.dungeon.get_enemy_coords()[1] -= 1
            return
        if direction == "up":
            self.dungeon.get_enemy_coords()[0] -= 1
            return
        else:
            self.dungeon.get_enemy_coords()[0] += 1
            return

    def different_positions(self):
        return self.dungeon.get_coords() == self.dungeon.get_enemy_coords()

    def start_fight_by_spell(self):
            while self.hero.get_mana() > 0:
                self.enemy.get_health() -= self.hero.get_damage()
                self.message_hero_cast()
                if not self.different_positions():
                    self.message_move_enemy()
                    self.move_enemy(self.give_moved_direction())
                else:
                    self.hero.get_health() -= self.enemy.get_damage()
                    self.message_enemy_hit()
                self.hero.get_mana() -= self.hero.get_spell().get_mana_cost()
            self.message_no_more_mana()
            self.start_fight_by_weapon()

    def start_fight_by_weapon(self):
        while self.hero.get_health() > 0 and self.enemy.get_health() > 0:
            self.enemy.get_health() -= self.hero.get_weapon().get_damage()
            self.message_use_weapon()
            self.hero.get_health() -= self.enemy.get_damage()
            self.message_enemy_hit()
        if self.hero.get_health() == 0:
            self.message_dead(self.hero.get_name())
        if self.enemy.get_health() == 0:
            self.message_dead("Enemy")

    def hero_attack(self, by="spell"):
        if self.hero.get_spell().get_damage() >= self.hero.get_weapon().get_damage():
            if self.check_range_attack():
                self.enemy = Enemy(100, 100, 20)
                self.message_start_fight()
                self.start_fight_by_spell()
            else:
                return "Nothing in casting range " + str(self.hero.get_spell().get_cast_range())
        else:
            self.start_fight_by_weapon()

    def check_range_attack(self):
        dy = self.dungeon.get_coords()[0]
        dx = self.dungeon.get_coords()[1]
        cast_range = self.hero.get_spell().get_cast_range()
        left_index = dx - cast_range
        right_index = dx + cast_range
        up_index = dy - cast_range
        down_index = dy + cast_range

        if left_index or up_index < 0:
            left_index, up_index = 0, 0
        if right_index >= len(self.dungeon.get_map()[dx][0]):
            right_index = len(self.dungeon.get_map()[dx][0]) - 1
        if down_index >= len(self.dungeon.get_map()):
            down_index = len(self.dungeon.get_map()) - 1

        for i in range(left_index, right_index):
            for j in range(up_index, down_index):
                if self.dungeon.get_map()[j][0][i] == "E":
                    self.dungeon.get_enemy_coords().append(j)
                    self.dungeon.get_enemy_coords().append(i)
                    return True
        return False
Ejemplo n.º 5
0
class DungeonsAndPythonsTests(unittest.TestCase):
    def setUp(self):
        self.hero = Hero("Bron", "Dragon", 100, 100, 2)
        self.dungeon = Dungeon("map2.txt")
        self.weapon = Weapon(name="The Axe of Destiny", damage=20)
        self.spell = Spell(name="Fireball", damage=30, mana_cost=50, cast_range=2)
        self.mana_potion = self.hero.mana
        self.health_potion = self.hero.health

    def test_known_as(self):
        self.assertEqual(self.hero.known_as(), "Bron the Dragon")

    def test_is_alive(self):
        self.assertTrue(self.hero.is_alive())

    def test_spawn_hero(self):
        self.dungeon.spawn()

    def test_get_position(self):
        self.dungeon.spawn()
        self.assertEqual(self.dungeon.get_position(), (0, 0))

    def test_move_right(self):
        self.dungeon.spawn()
        self.dungeon.move_hero("right")
        # self.dungeon.print_map()
        self.assertFalse(self.dungeon.move_hero("right"))

    def test_move_up(self):
        self.dungeon.spawn()
        self.dungeon.move_hero("up")
        self.assertFalse(self.dungeon.move_hero("up"))

    def test_move_left(self):
        self.dungeon.spawn()
        self.dungeon.move_hero("left")
        self.assertFalse(self.dungeon.move_hero("left"))

    def test_move_down(self):
        self.dungeon.spawn()
        self.dungeon.move_hero("down")
        self.assertFalse(self.dungeon.move_hero("down"))
Ejemplo n.º 6
0
from dungeons import Dungeon

dungeon = Dungeon({'style': 'dungeon', 'purpose': 'stronghold'})

dungeon.base_dungeon()

dungeon.populate_dungeon('immortal guardians', 3, 'haunted')
dungeon.populate_dungeon('hideout', 2, 'bandits')

dungeon.write_module()

dungeon.save_dungeon_image()
Ejemplo n.º 7
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()
 def setUp(self):
     self.dungeon = Dungeon("level1.txt")
     self.hero = Hero("Arthur", "knight", 100, 100, 2)
     self.my_map = "S.##.....T\n#T##..###.\n#.###E###E\n#.E...###.\n###T#####G\n"
     self.my_matrix = [['S', '.', '#', '#', '.', '.', '.', '.', '.', 'T'], ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'], ['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'], ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'], ['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']]
class TestDungeons(unittest.TestCase):
    def setUp(self):
        self.dungeon = Dungeon("level1.txt")
        self.hero = Hero("Arthur", "knight", 100, 100, 2)
        self.my_map = "S.##.....T\n#T##..###.\n#.###E###E\n#.E...###.\n###T#####G\n"
        self.my_matrix = [['S', '.', '#', '#', '.', '.', '.', '.', '.', 'T'], ['#', 'T', '#', '#', '.', '.', '#', '#', '#', '.'], ['#', '.', '#', '#', '#', 'E', '#', '#', '#', 'E'], ['#', '.', 'E', '.', '.', '.', '#', '#', '#', '.'], ['#', '#', '#', 'T', '#', '#', '#', '#', '#', 'G']]

    def test_init(self):
        self.assertTrue(isinstance(self.dungeon, Dungeon))
        self.assertEqual(self.dungeon.my_map, self.my_map)
        self.assertEqual(self.my_matrix, self.dungeon.matrix)

    def test_matrix_to_map(self):
        self.assertEqual(self.dungeon.matrix_to_map(), self.my_map)

    def test_map_to_matrix(self):
        self.assertEqual(self.dungeon.map_to_matrix(), self.my_matrix)

    def test_get_hero_position(self):
        self.dungeon.spawn(self.hero)
        self.assertEqual(self.dungeon.get_hero_position(), (0, 0))
        self.dungeon.spawn(self.hero)
        self.dungeon.spawn(self.hero)
        self.assertEqual(self.dungeon.get_hero_position(), (0, 4))

    def test_move_hero(self):
        self.dungeon.spawn(self.hero)
        self.assertFalse(self.dungeon.move_hero('left'))