コード例 #1
0
def game_loop():
    creatures = [
        Creature('Toad', 1),
        Creature('Tiger', 12),
        Creature('Bat', 3),
        Creature('Dragon', 50),
        Creature('Evil Wizard', 1000)
    ]

    hero = Wizard('Gandalf', 75)

    while True:

        active_creature = random.choice(creatures)
        print('A {} of level {} has appeared from the forbidden forest...'.format(active_creature.name, active_creature.level))

        cmd = input('Do you want to [a]ttack, [l]ook around or [r]un away?')
        if cmd == 'a':
            if hero.attack(active_creature):
                creatures.remove(active_creature)
            else:
                print('{} has been defeated and must hide in the forest to regain his strength'.format(hero.name))
                time.sleep(5)
                print('{} has regained his strength and is ready to wander forth'.format(hero.name))
        elif cmd == 'l':
            print('{} has a look around and sees...')
            for c in creatures:
                print('     *       {} of level {}'.format(c.name, c.level))
        elif cmd == 'r':
            print('The Wizard has become unsure of his power and flees...')
        else:
            print('Exiting game, bye!')
            break
コード例 #2
0
def main():
    print_header()

    creatures = [
        Creature("Bat", 5),
        Creature("Toad", 1),
        Creature("Tiger", 12),
        Dragon("Black Dragon", 50, False),
        Wizard("Evil Wizard", 1000)
    ]

    hero = Wizard("Harry", 75)

    while True:
        active_creature = random.choice(creatures)
        print(
            f"A {active_creature.name} of level {active_creature.level} has appear from a dark and foggy forest...\n"
        )

        cmd = input("Do you [a]ttack, [r]unaway, or [l]ook around? ")
        if cmd == "a":
            if hero.attack(active_creature):
                creatures.remove(active_creature)
                print(f"The wizard defeated {active_creature.name}")
            else:
                print(
                    f"The wizard has been defeat by the powerful {active_creature.name}"
                )

        elif cmd == "r":
            print("The wizard has become unsure of his power and flees!!!")

        elif cmd == "l":
            print(
                f"The wizard {hero.name} takes in the surroundings and sees: ")
            for c in creatures:
                print(f" * {c.name} of level {c.level}")

        else:
            print("OK, exiting game ... bye!")
            break

        if not creatures:
            print("You've defeated all the creatures, well done!")
            break

    print()
コード例 #3
0
ファイル: program.py プロジェクト: flenoir/wizzard_app
def main_loop():

    creatures = [
        Small_creatures("Toad", 1),
        Creature("Tiger", 12),
        Small_creatures("wolf", 9),
        Creature("crocodile", 20),
        Small_creatures("dog", 6),
        Creature("dwarf", 30),
        Dragon("Dragon", 50, 20, True),
        Wizard("Evil Wizard", 1000)
    ]

    hero = Wizard("gandolf", 75)

    # print(creatures)

    while True:

        active_creature = random.choice(creatures)
        print('A {} of level {} has appeared from the foggy forest'.format(
            active_creature.name, active_creature.level))
        print('')

        cmd = input(
            "What do you want to do ? [a]ttack, [r]un or [l]ookaround ")

        if cmd == "a":
            if hero.attack(active_creature):
                creatures.remove(active_creature)
            else:
                print("The wizard needs to rest for a while")
                time.sleep(5)
                print("Wizard returns revitalized")
        elif cmd == "r":
            print("The Wizard runs beacuase he doesn't want to fight")
        elif cmd == "l":
            print("the wizard {} lookaround and sees :".format(hero.name))
            for c in creatures:
                print("* A {} of level {}".format(c.name, c.level))
        else:
            print("ok exiting")
            break

        if not creatures:
            print("The Wizard {} has defeated all creatures".format(hero.name))
コード例 #4
0
ファイル: battle.py プロジェクト: Atropos148/Jumpstart10apps
def game_loop():
    creatures = [
        SmallAnimal('Toad', 1),
        Creature('Tiger', 12),
        SmallAnimal('Bat', 3),
        Dragon('Red Dragon', 50, 75, True),
        Wizard('Evil Wizard', 150)
    ]

    hero = Wizard('Gandelf', 75)

    while True:

        active_creature = random.choice(creatures)
        print(
            f'A {active_creature.name} of level {active_creature.level} has appeared from the forest.'
        )

        cmd = input("Do you [a]ttack, [r]un away or [l]ook around? ")
        print()
        if cmd == 'a':
            if hero.attack(active_creature):
                creatures.remove(active_creature)
            else:
                print('The wizard runs away to recover from battle...')
                time.sleep(3)
                print('The wizard returns, ready to fight!')

        elif cmd == 'r':
            print('The Wizard is unsure of his power and runs away!')

        elif cmd == 'l':
            print(f'Wizard {hero.name} takes a long look around and sees:')
            for c in creatures:
                print(f'A {c.name} of level {c.level}')
        else:
            print('Exiting game, bye')
            break

        if not creatures:
            print('You killed all the creatures!')
            break

        print()
コード例 #5
0
def game_loop():

    creatures = [
        SmallAnimal('Toad', 1),
        Creature('Tiger', 12),
        SmallAnimal('Bat', 3),
        Dragon('Dragon', 50, 20, True),
        Wizard('Evil Wizard', 100)
    ]

    hero = Wizard('Magic Mike', 75)

    while True:

        active_creature = random.choice(creatures)
        print('A {} of level {} has appeared in front of you'.format(active_creature.name, active_creature.level))

        cmd = input('Do you [a]ttack, [r]unaway, or [l]ook around?')
        if cmd == 'a':
            if hero.attack(active_creature):
                creatures.remove(active_creature)
            else:
                print('You run away to recuperate')
                time.sleep(5)
                print('You are now ready to go forth again')
        elif cmd == 'r':
            print('You flee in terror, screaming like a frightened child.')
        elif cmd == 'l':
            print('You look around and see:')
            for c in creatures:
                print(' * A {} of level {}'.format(c.name, c.level))
        else:
            print('Exiting Game')
            break

        if not creatures:
            print("You've done it! All your enemies have been vanquished!")
            break

        print()
コード例 #6
0
ファイル: generator.py プロジェクト: nyalldawson/dwarf_mine
    def build_mine(self, screen, pad):

        m = Mine(screen, pad, self.width, self.height)

        tribe_population = self.args.miners or random.randint(1, 30)

        tribe_width = int(m.width / (self.args.tribes * 2 - 1))
        for t in range(self.args.tribes):
            new_tribe = random.choice(TRIBE_CLASSES)(t)

            new_tribe.min_x = tribe_width * new_tribe.id * 2
            new_tribe.max_x = tribe_width * (new_tribe.id * 2 + 1) - 1
            new_tribe.color = COLORS[t]
            new_tribe.leader_color = KING_COLORS[t]
            new_tribe.name = (NAMES[t] + ' ' + new_tribe.name).strip()
            m.tribes.append(new_tribe)

            creatures = new_tribe.populate(tribe_population)
            for c in creatures:
                m.add_creature(c)

        #for i in range(miner_count):
        #    tribe = random.choice(m.tribes)
        #    x = random.randint(tribe.min_x, tribe.max_x)

        #    creature = tribe.create_creature(x=x, y=0, tribe=tribe)
        #    m.add_creature(creature)

        for i in range(random.randint(4, 10)):
            hole_size = random.randint(4, 8)
            m.create_cave(random.randint(0, m.width - 1),
                          random.randint(0, m.height - 1), hole_size)

        outcast_tribe = Tribe(-1)
        outcast_tribe.name = 'Outcast'
        saboteur_count = self.args.saboteurs or random.randint(1, 3)
        for i in range(saboteur_count):
            saboteur = Saboteur(random.randint(0, m.width - 1),
                                int(m.height / 2),
                                tribe=outcast_tribe)
            m.add_creature(saboteur)

        wizard_count = self.args.wizards or random.randint(1, 5)
        for i in range(wizard_count):
            wizard = Wizard(
                random.randint(0, m.width - 1),
                random.randint(math.ceil(m.height / 3), m.height - 1))
            m.add_creature(wizard)

    #   def make_explore_action():
    #       return ExploreAction()

    #snake_count = self.args.snakes or random.randint(1, 5)
    #for i in range(snake_count):
    #    tribe = random.choice([t for t in m.tribes if Snake in t.creatures])
    #    x = random.randint(tribe.min_x, tribe.max_x)
    #    snake = Snake(x, 0, tribe=tribe)

    #    snake.default_action = make_explore_action
    #    snake.push_action(ExploreAction())
    #    if snake.has_trait(Contagious):
    #        snake.color = KING_COLORS[tribe.id]
    #    else:
    #        snake.color = tribe.color

#     #     snake = Snake(random.randint(0, m.width - 1), random.randint(math.ceil(m.height / 5), m.height - 1))
#    m.add_creature(snake)

        treasure_count = self.args.treasures or random.randint(1, 10)
        for i in range(treasure_count):
            treasure = Treasure(random.randint(0, m.width - 1),
                                random.randint(10, m.height - 1))
            m.add_item(treasure)
            map_item = Map(random.randint(0, m.width - 1),
                           random.randint(5, m.height - 1), treasure)
            m.add_item(map_item)

    #  for t in m.tribes:
    #      king_count = int(self.args.kings) if self.args.kings is not None else 1
    #      for i in range(king_count):
    #          x = random.randint(t.min_x, t.max_x)
#
#          king = DwarfKing(x, 0, t)
#          king.color = KING_COLORS[t.id]
#          m.add_creature(king)
#
        return m
コード例 #7
0
def game_loop():
    creatures = \
        [SmallAnimal('Toad', 1),
         SmallAnimal('Bat', 3),
         Creature('Wolf', 12),
         Dragon('Dragon', 50, scaliness=20, breathes_fire=True),
         Wizard('Evil Wizard', 500)]
    settings = [
        'Misty forest', 'Dark lake', 'Rickety bridge', 'Mysterious cave',
        'Derelict shack'
    ]
    character_name = input('Please input your name: ')
    character = Wizard(character_name, 75)

    print()
    print('The Wizard {0} starts their journey seeking after the evil wizard. '
          '{0} gets the feeling that evil creatures are close.'.format(
              character_name))
    print('{} is level {}'.format(character_name, character.level))
    print()

    while creatures:

        active_creature = random.choice(creatures)
        active_setting = random.choice(settings)

        print('{} stumbles upon a {}'.format(character_name, active_setting))
        print()
        print('A level {0} {1} appears from the {2}.'.format(
            active_creature.level, active_creature.name, active_setting))
        print()

        action = input(
            'Would you like to [A]ttack, [R]un, [L]ook around or E[x]it game?: '
        )
        print()
        if action.lower().strip() == 'a':
            if character.attack(active_creature):
                creatures.remove(active_creature)
                character.level = character.level + (active_creature.level *
                                                     0.5)
                print('{} has grown to level {}.'.format(
                    character_name, character.level))
                print('-----------------------')
            else:
                print('{} cowers and flees to rest and recover.'.format(
                    character_name))
                time.sleep(10)
                character.level = character.level + (active_creature.level / 3)
                print(
                    '{} returns, having grown to level {} from the mistakes of the previous battle.'
                    .format(character_name, character.level))
                print('-----------------------')
        elif action.lower().strip() == 'r':
            print(
                'The Wizard {} fears their powers are not strong enough to match the {} and flees.'
                .format(character_name, active_creature.name))
            print('-----------------------')
        elif action.lower().strip() == 'l':
            print('{} takes in the {} and sees foes circling.'.format(
                character_name, active_setting))
            print('The remaining foes: ')
            for c in creatures:
                print('The {} of level {}.'.format(c.name, c.level))
            print('-----------------------')
        elif action.lower().strip() == 'x':
            print('Okay, leaving the game')
            break
        else:
            print('Please enter a valid command.')

        if not creatures:
            print(
                '{} has been triumphant, all the evil creatures have been banished!'
                .format(character_name))
コード例 #8
0
def gen_wizard(name):
    return Wizard(name, 20)