コード例 #1
0
ファイル: game.py プロジェクト: manuelpepe/TextAdventureGame
def play():
    """
    Loop del juego
    """
    print("\n====================================================================")
    world.create_world()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        if player.is_alive() and not player.victory:
            print("\nElegí una acción:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input("\nAcción: ")
            print("====================================================================")
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    if action_input == 'i':
                        print(room.intro_text())
                    break

    if not player.is_alive():
        print("PERDISTE!\nIgual no te preocupes, la princesa estaba en otro castillo")
    elif player.victory:
        print("Lo siento, la princesa esta en otro castillo!")
コード例 #2
0
def play():

    print(intro_text)

    world.create_world()
    player = Player(world.starting_position)

    last_input = None

    # for damage in [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20]:
    #     print("{0:>3s}".format(str(damage)), end="")
    #     for drunkness in range(0, 6):
    #         print("{0:>3s}".format(str(player.get_damage(damage, drunkness))), end="")
    #     print("\n")


    while player.is_alive() and not player.victory:

        room = world.tile_at(player.x, player.y)
        room.visited = True
        print(room.intro_text(player))

        # Le temps passant l'alcolémie du joueur passe
        if player.drunkness > 0 and last_input != "b":
            player.drunkness *= 0.85 if player.drunkness>0.5 else 0

        # Voir l'inventaire n'est pas considéré comme agissant dans le jeu
        if last_input != "i":
            room.modify_player(player)

        if player.is_alive() and not player.victory:
            print("Vos points de vie : {}".format(player.hp))
            if player.drunkness > 0:
                print("Ébriété : {}".format(round(player.drunkness,2)))

            print("\nChoisir une action:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)

            correct_input = False
            while not correct_input:
                action_input = input('\nAction: ')
                for action in available_actions:
                    if action_input == action.hotkey:
                        player.do_action(action, **action.kwargs)
                        correct_input = True
                        last_input = action.hotkey
                        break

    if not player.is_alive():
        print("""
        Vous venez de rejoindre la horde des pirates mort-vivants qui hantent
        cette île maudite qui jadis come vous avaient eu le rêve fou de quitter
        ce lieu avec le trésor de Barbe Noire...

        Le pirate qui repartira vivant est, semble t-il, pas encore né !
        """)
コード例 #3
0
def game_loop():
    game_started = False

    while not game_started:
        user_input = input('New game(1)\nLoad game (2)\n')

        if user_input == '1':
            world.create_world(10)
            player_pos = world.spawn_player()
            game_started = True
            logger.warning('New game started')
        elif user_input == '2':
            try:
                player_pos = world.load()
                game_started = True
                logger.warning('Game loaded')
            except RuntimeError as error:
                logger.warning(error)

    won = False
    lose = False
    while not (won or lose):
        if world.is_trap_around(player_pos):
            logger.warning('There is a trap within one square from you!')
        else:
            logger.warning('No traps around.')
        if world.is_treasure_around(player_pos):
            logger.warning('There is a treasure within one square from you!')
        else:
            logger.warning('No treasures around.')

        input_is_valid = False
        while not input_is_valid:
            logger.warning(
                'Your move (w/a/s/d)? (Input \'save\' to save game)')
            user_input = input()

            input_is_valid = True
            if user_input in directions.keys():
                world.move_player(player_pos, directions[user_input])
            elif user_input == 'save':
                world.save(player_pos)
                logger.warning('Game saved.')
            else:
                logger.warning('Invalid input. Try again.')
                input_is_valid = False

        won = world.is_found_treasure(player_pos)
        lose = world.is_trapped(player_pos)

    if won:
        logger.warning('You won!')
    else:
        logger.warning('You lose!')

    world.print_world(player_pos)
コード例 #4
0
def play():
    print("Escape from Cave Terror!")
    world.create_world()
    player = Player()
    while player.is_alive() and not player.victory:
        room = world.tile_at(player.x, player.y)
        print(room.intro_text())
        room.modify_player(player)
        if player.is_alive() and not player.victory:
            choose_action(room, player)
        elif not player.is_alive():
            print("Your journey has come to an early end!")
コード例 #5
0
    def start(self, button=None):
        """Initialisation du jeu en début de chaque partie"""
        world.create_world()

        # Joueur au début du jeu
        self.player = Player(world.starting_position)
        # Lieu de démarrage
        self.room = world.tile_at(self.player.x, self.player.y)
        self.room.visited = True
        # Texte de présentation du jeu
        self._intro_text.set_text(Game.begin_text)
        # Update clonne gauche : map + status + actions
        self.update_controls()
コード例 #6
0
ファイル: test_search.py プロジェクト: ligaoz/Robot
def test_search():

    data, size, goal, r = parseLine(
        "8x8 \nw 1,2\nw 1,3\nw 1,4\nw 1,5\n robot 4,2\ngoal 7,0")
    world = create_world(size, data, r, goal)
    world.print_world()
    stack = linked_list()
    r2d2 = robot(r)
    search(r2d2.x, r2d2.y, world, stack)
コード例 #7
0
ファイル: game.py プロジェクト: manuelpepe/TextAdventureGame
def play():
    """
    Loop del juego
    """
    print(
        "\n===================================================================="
    )
    world.create_world()
    player = Player()
    room = world.tile_exists(player.location_x, player.location_y)
    print(room.intro_text())

    while player.is_alive() and not player.victory:
        room = world.tile_exists(player.location_x, player.location_y)
        room.modify_player(player)
        if player.is_alive() and not player.victory:
            print("\nElegí una acción:\n")
            available_actions = room.available_actions()
            for action in available_actions:
                print(action)
            action_input = input("\nAcción: ")
            print(
                "===================================================================="
            )
            for action in available_actions:
                if action_input == action.hotkey:
                    player.do_action(action, **action.kwargs)
                    if action_input == 'i':
                        print(room.intro_text())
                    break

    if not player.is_alive():
        print(
            "PERDISTE!\nIgual no te preocupes, la princesa estaba en otro castillo"
        )
    elif player.victory:
        print("Lo siento, la princesa esta en otro castillo!")
コード例 #8
0
ファイル: pogame.py プロジェクト: imanehmiddou/PoGame
def main():
    # Création du "monde" tel que nous le définissons
    world = create_world()
    # Création des surfaces de dessin
    screen, background = create_screen(world)
    # Création d'une horloge
    clock = pygame.time.Clock()
    # Coordonnées [x, y] du joueur
    player = [0, 0]

    # Les variables qui nous permettent de savoir si notre programme est en cours d'exécution ou s'il doit se terminer.
    alive = True
    running = True

    # On met à jour ce qu'on affiche sur l'écran, et on "pousse" l'aiguille de l'horloge d'un pas.
    update_screen(screen, background, world, player)
    clock.tick()

    # Boucle "quasi" infinie, qui s'arrêtera si le joueur est mort, ou si l'arrêt du programme est demandé.
    while alive and running:
        # À chaque itération, on demande à pygame quels "évènements" se sont passés. Ces évènements sont l'interface
        # qui permet d'interragir avec l'extérieur du programme, et en particulier l'utilisateur (qui utilisera son
        # clavier.
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                break
            elif event.type == pygame.KEYDOWN:
                if event.type == pygame.K_DOWN:
                    if position[1] < HEIGHT - 1:
                        position = (position[0], position[1] + 1)

                elif event.type == pygame.K_UP:
                    if position[1] > 0:
                        position = (position[0], position[1] - 1)

                elif event.type == pygame.K_LEFT:
                    if position[0] > 0:
                        position = (position[0] - 1, position[1])

                elif event.type == pygame.K_RIGHT:
                    if position[0] < WIDTH - 1:
                        position = (position[0] + 1, position[1])

        # On met à jour ce qu'on affiche sur l'écran, et on "pousse" l'aiguille de l'horloge d'un pas.
        update_screen(screen, background, world, player)
        clock.tick()
コード例 #9
0
def main():
    # Création du "monde" tel que nous le définissons
    world = create_world()
    # Création des surfaces de dessin
    screen, background = create_screen(world)
    # Création d'une horloge
    clock = pygame.time.Clock()
    # Coordonnées [x, y] du joueur
    position = [0, 0]
    inventory = []

    # Les variables qui nous permettent de savoir si notre programme est en cours d'exécution ou s'il doit se terminer.
    alive = True
    running = True

    # On met à jour ce qu'on affiche sur l'écran, et on "pousse" l'aiguille de l'horloge d'un pas.
    update_screen(screen, background, world, position, inventory)
    clock.tick()

    # Boucle "quasi" infinie, qui s'arrêtera si le joueur est mort, ou si l'arrêt du programme est demandé.
    while alive and running:
        # À chaque itération, on demande à pygame quels "évènements" se sont passés. Ces évènements sont l'interface
        # qui permet d'interragir avec l'extérieur du programme, et en particulier l'utilisateur (qui utilisera son
        # clavier, par exemple).
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                # L'utilisateur souhaite fermer la fenêtre ou quitter par un autre moyen (menus ...).
                # À la prochaine itération de notre boucle principale, la condition sera fausse et le programme va se
                # terminer.
                running = False
            elif event.type == pygame.KEYDOWN:
                # Une touche du clavier a été pressée.
                if event.key == pygame.K_q:
                    # L'utilisateur a appuyé sur "Q", pour Quitter.
                    # À la prochaine itération de notre boucle principale, la condition sera fausse et le programme va
                    # se terminer.
                    running = False
                elif event.key == pygame.K_UP:
                    if position[1] > 0:
                        position = [position[0], position[1] - 1]
                elif event.key == pygame.K_DOWN:
                    if position[1] < WORLD_HEIGHT - 1:
                        position = [position[0], position[1] + 1]
                elif event.key == pygame.K_LEFT:
                    if position[0] > 0:
                        position = [position[0] - 1, position[1]]
                elif event.key == pygame.K_RIGHT:
                    if position[0] < WORLD_WIDTH - 1:
                        position = [position[0] + 1, position[1]]
                elif event.key == pygame.K_SPACE:
                    room = get_room(world, position[0], position[1])
                    if len(room) > 0:
                        item = room[0]
                        room, inventory = transfer_item(room, inventory, item)
            elif event.type == pygame.KEYUP:
                # Une touche du clavier a été relachée.
                pass

        # On met à jour ce qu'on affiche sur l'écran, et on "pousse" l'aiguille de l'horloge d'un pas.
        update_screen(screen, background, world, position, inventory)
        clock.tick()

        if len(inventory) >= 10:
            # Le joueur a gagné !
            break
コード例 #10
0
ファイル: server.py プロジェクト: MrSilent/Craft
 def get_default_block(self, x, y, z):
     p, q = chunked(x), chunked(z)
     chunk = world.create_world(p, q)
     return chunk.get((x, y, z), 0)
コード例 #11
0
ファイル: pogame.py プロジェクト: ImaneHadj/PoGame
def main():

    inventory = []

    # Création du "monde" tel que nous le définissons
    world = create_world()
    # Création des surfaces de dessin
    screen, background = create_screen(world)
    # Création d'une horloge
    clock = pygame.time.Clock()
    # Coordonnées [x, y] du joueur
    player = [0, 0]
    # initialisation de coordonnées aléatoires pour le mechant
    mechant_x = random.randint(0, WORLD_WIDTH - 1)
    mechant_y = random.randint(0, WORLD_HEIGHT - 1)
    mechant = [mechant_x, mechant_y]
    # Les variables qui nous permettent de savoir si notre programme est en cours d'exécution ou s'il doit se terminer.
    alive = True
    win = False
    running = True
    status = "start"
    # On met à jour ce qu'on affiche sur l'écran, et on "pousse" l'aiguille de l'horloge d'un pas.
    update_screen(screen, background, world, player, mechant, status)
    clock.tick()

    # Boucle "quasi" infinie, qui s'arrêtera si le joueur est mort, ou si l'arrêt du programme est demandé.

    while running:
        # À chaque itération, on demande à pygame quels "évènements" se sont passés. Ces évènements sont l'interface
        # qui permet d'interragir avec l'extérieur du programme, et en particulier l'utilisateur (qui utilisera son
        # clavier, par exemple).

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                # L'utilisateur souhaite fermer la fenêtre ou quitter par un autre moyen (menus ...).
                # À la prochaine itération de notre boucle principale, la condition sera fausse et le programme va se
                # terminer.
                running = False
            elif event.type == pygame.KEYDOWN:
                # Une touche du clavier a été pressée.
                if event.key == pygame.K_q:
                    # L'utilisateur a appuyé sur "Q", pour Quitter.
                    # À la prochaine itération de notre boucle principale, la condition sera fausse et le programme va
                    # se terminer.
                    running = False
                if event.key == pygame.K_SPACE:
                    status = "play"
                    continue  # passer à la prochaine iteration
                if status == "play":
                    if event.key == pygame.K_UP:
                        if player[1] > 0:
                            player = (player[0], player[1] - 1)
                            mechant = bougerLeMechant(mechant)
                    elif event.key == pygame.K_DOWN:
                        if player[1] < WORLD_HEIGHT - 1:
                            player = (player[0], player[1] + 1)
                            mechant = bougerLeMechant(mechant)
                    elif event.key == pygame.K_LEFT:
                        if player[0] > 0:
                            player = (player[0] - 1, player[1])
                            mechant = bougerLeMechant(mechant)
                    elif event.key == pygame.K_RIGHT:
                        if player[0] < WORLD_WIDTH - 1:
                            player = (player[0] + 1, player[1])
                            mechant = bougerLeMechant(mechant)
                    elif event.key == pygame.K_i:
                        if world[player[1]][player[0]]:
                            print(world[player[1]][player[0]][0], "trouvé")
                        else:
                            print("this is empty")
                    elif event.key == pygame.K_d:
                        if inventory:
                            world[player[1]][player[0]] = inventory[0]
                            inventory.pop(0)
                        else:
                            print("inventory is empty")
                    elif event.key == pygame.K_p:
                        if world[player[1]][player[0]]:
                            inventory.append(world[player[1]][player[0]])
                            world[player[1]][player[0]] = []
                        else:
                            print("this is empty")
                    elif event.key == pygame.K_v:
                        if inventory:
                            print(inventory)
                        else:
                            print("inventory is empty")

        # On vérifie si le joueur a gagné
        if inventory:
            s = 0
            for elt in inventory:
                s += elt[0]
            if s >= 100:
                win = True
                status = "gagné"
        # On vérifie si le joueur a perdu
        if mechant[0] == player[0] and mechant[1] == player[1]:
            alive = False
            status = "perdu"
        # On met à jour ce qu'on affiche sur l'écran, et on "pousse" l'aiguille de l'horloge d'un pas.
        update_screen(screen, background, world, player, mechant, status)
        clock.tick()