def game_starter():
        """
        Introduces the player to the game. Creates an adventurer with the given name.
        Creates a dungeon of given dimensions. Allows the player to move and play the game.
        """
        print("Welcome to our Dungeon game!")
        name = str(input("What's your name? "))
        column_count = int(
            input("Please input an integer as the number of columns dungeon "))
        row_count = int(
            input(
                "Please input an integer as the number of rows of the dungeon "
            ))
        dungeon = Dungeon(column_count, row_count)
        dungeon.dungeon_generator()
        adventurer = Adventurer(name)
        hit_point = adventurer.hit_points
        pillar_collected = adventurer.pillar_collected
        healing_potion_count = adventurer.healing_potion_count
        vision_potion_count = adventurer.vision_potion_count
        curr_x, curr_y = dungeon.entrance_exit_pos()[0]
        exit_x, exit_y = dungeon.entrance_exit_pos()[1]
        dire_map = {"l": [0, -1], "r": [0, 1], "u": [-1, 0], "d": [1, 0]}

        while True:
            move = input(
                "Where would you like to move next, please enter 'l' for left, 'r' for 'right', 'u' for 'up',"
                " 'd' for 'down', 'e' for exit, 's' for showing the whole dungeon map"
            )
            if move == "e":
                break
            if move == "s":
                print(dungeon)
            if move not in dire_map:
                print(
                    f"Please input a valid string among {dire_map.keys()}, e , s"
                )
                continue
            dire = dire_map[move]
            next_x = curr_x + dire[0]
            next_y = curr_y + dire[1]
            if DungeonAdventure.if_passable(dungeon, curr_x, curr_y, next_x,
                                            next_y, column_count, row_count):
                next_room = dungeon.room_list[next_x][next_y]
                curr_room = next_room
                if hit_point < 0:
                    print("You have lost all the hit points.")
                    break
                print(
                    f"=============== current room content is {curr_room.room_content}==============="
                )
                if curr_room.room_content == "X":
                    pit_point = random.randint(1, 20)
                    hit_point = hit_point - pit_point
                    curr_room.room_content = " "
                    print(f'Your current hit points are {hit_point}')
                elif curr_room.room_content == "H":
                    healing_point = random.randint(1, 40)
                    hit_point = hit_point + healing_point
                    print(f'Your current hit points are {hit_point}')
                    healing_potion_count += 1
                    curr_room.room_content = " "
                elif curr_room.room_content == "A" or curr_room.room_content == "E" or curr_room.room_content == "I" or \
                        curr_room.room_content == "P":
                    pillar_collected.append(curr_room.room_content)
                    curr_room.room_content = " "
                elif curr_room.room_content == "V":
                    vision_potion_count += 1
                    print(dungeon.get_vision_potion_rooms())
                adventurer.hit_points = hit_point
                curr_x, curr_y = next_x, next_y
                if (curr_x, curr_y) == (exit_x, exit_y):
                    print("Congratulations! You have reach the destination!")
                    break
                print(f"{name} is in ({curr_x}, {curr_y})")
                print(adventurer)
            else:
                print("You can't move in this direction")
    def main(self):
        """
        This is the main method.
        """
        global my_image, adventurer_i_index, adventurer_j_index, dng, exit_i_index, exit_j_index, n_rows, n_cols
        adventurer_i_index = 0
        adventurer_j_index = 0

        # Create tk windows and bind key strokes
        DungeonGui.create_tk_windows(self)

        # Create GUI rooms
        dungeon = DungeonGui(n_rows, n_cols)
        dungeon.create_rooms()

        # Populate the GUI rooms with dungeon content
        dng = Dungeon(n_rows, n_cols)
        dng.dungeon_generator()
        print(dng)
        for i in range(0, n_rows):
            for j in range(0, n_cols):
                row_index = i
                col_index = j
                content = dng.room_list[i][j].room_content

                if content == 'i':
                    dungeon.create_content(row_index, col_index, content)

                if content == 'O':
                    dungeon.create_content(row_index, col_index, content)

                east_door_symbol = dng.room_list[i][j].room_matrix[1][2]
                #                dungeon.create_east_door(row_index, col_index, east_door_symbol)

                west_door_symbol = dng.room_list[i][j].room_matrix[1][0]
                #                dungeon.create_west_door(row_index, col_index, west_door_symbol)

                north_door_symbol = dng.room_list[i][j].room_matrix[0][1]
                #                dungeon.create_north_door(row_index, col_index, north_door_symbol)

                south_door_symbol = dng.room_list[i][j].room_matrix[2][1]
                #                dungeon.create_south_door(row_index, col_index, south_door_symbol)

                if content == 'i':
                    adventurer_i_index = i
                    adventurer_j_index = j
                    my_image = dungeon.create_adventurer(
                        adventurer_j_index * 100 + 32,
                        adventurer_i_index * 100 + 32)

                if content == 'O':
                    exit_i_index = i
                    exit_j_index = j
                    #print(exit_i_index,exit_j_index)
        """
         Displays
        """
        label1a = tk.Label(my_window, text='INSTRUCTIONS:', fg="blue")
        label1a.config(font=('Arial', 15))
        my_canvas.create_window(950, 50, window=label1a)

        label1b = tk.Label(my_window, text='Use Keyboard Arrow Keys')
        label1b.config(font=('Arial', 15))
        my_canvas.create_window(950, 75, window=label1b)

        label2 = tk.Label(my_window, text='Entrance: i, Exit: O')
        label2.config(font=('Arial', 15))
        my_canvas.create_window(950, 100, window=label2)

        label3 = tk.Label(my_window, text='Pillars and Doors Hidden')
        label3.config(font=('Arial', 15))
        my_canvas.create_window(950, 150, window=label3)

        label3 = tk.Label(my_window, text='Gather Pillars and Reach O')
        label3.config(font=('Arial', 15))
        my_canvas.create_window(950, 180, window=label3)

        label7 = tk.Label(my_window, text='  SCORE:', fg='blue')
        label7.config(font=('Arial', 15))
        my_canvas.create_window(950, 300, window=label7)

        my_window.mainloop()  # enter main loop
예제 #3
0
    def main(self):
        """
        This is the main method and Entry point for the program.
        """
        global my_image, adventurer_i_index, adventurer_j_index, dng, exit_i_index, exit_j_index, n_rows, n_cols
        adventurer_i_index = 0
        adventurer_j_index = 0

        # Create tk windows and bind key strokes
        DungeonGui.create_tk_windows(self)

        # Create GUI rooms
        dungeon = DungeonGui(n_rows, n_cols)
        dungeon.create_rooms()

        # Populate the GUI rooms with dungeon content
        dng = Dungeon(n_rows, n_cols)
        dng.dungeon_generator()
        print(dng)
        for i in range(0, n_rows):
            for j in range(0, n_cols):
                row_index = i
                col_index = j
                content = dng.room_list[i][j].room_content
                dungeon.create_content(row_index, col_index, content)

                east_door_symbol = dng.room_list[i][j].room_matrix[1][2]
                dungeon.create_east_door(row_index, col_index,
                                         east_door_symbol)

                west_door_symbol = dng.room_list[i][j].room_matrix[1][0]
                dungeon.create_west_door(row_index, col_index,
                                         west_door_symbol)

                north_door_symbol = dng.room_list[i][j].room_matrix[0][1]
                dungeon.create_north_door(row_index, col_index,
                                          north_door_symbol)

                south_door_symbol = dng.room_list[i][j].room_matrix[2][1]
                dungeon.create_south_door(row_index, col_index,
                                          south_door_symbol)

                if content == 'i':
                    adventurer_i_index = i
                    adventurer_j_index = j
                    my_image = dungeon.create_adventurer(
                        adventurer_j_index * 100 + 32,
                        adventurer_i_index * 100 + 32)

                if content == 'O':
                    exit_i_index = i
                    exit_j_index = j
                    #print(exit_i_index,exit_j_index)
        """
         Displays
        """
        label1a = tk.Label(my_window, text='INSTRUCTIONS:', fg="blue")
        label1a.config(font=('Arial', 15))
        my_canvas.create_window(950, 50, window=label1a)

        label1b = tk.Label(my_window, text='Use Keyboard Arrow Keys')
        label1b.config(font=('Arial', 15))
        my_canvas.create_window(950, 75, window=label1b)

        label2 = tk.Label(my_window, text='Entrance: i, Exit: O')
        label2.config(font=('Arial', 15))
        my_canvas.create_window(950, 100, window=label2)

        label2a = tk.Label(my_window, text="Pillars: A, E, I, P")
        label2a.config(font=('Arial', 15))
        my_canvas.create_window(950, 125, window=label2a)

        label3 = tk.Label(my_window, text='North/South Doors: Green')
        label3.config(font=('Arial', 15))
        my_canvas.create_window(950, 150, window=label3)

        label4 = tk.Label(my_window, text='East/West Doors: Blue')
        label4.config(font=('Arial', 15))
        my_canvas.create_window(950, 175, window=label4)

        label5 = tk.Label(my_window, text='No Door => Closed Wall')
        label5.config(font=('Arial', 15))
        my_canvas.create_window(950, 200, window=label5)

        label6 = tk.Label(my_window, text='Two Adj Doors => Path Exists')
        label6.config(font=('Arial', 15))
        my_canvas.create_window(950, 225, window=label6)

        label6a = tk.Label(my_window, text='Adventurer: Person Image')
        label6a.config(font=('Arial', 15))
        my_canvas.create_window(950, 250, window=label6a)

        label7 = tk.Label(my_window, text='  FINAL SCORE:', fg='blue')
        label7.config(font=('Arial', 15))
        my_canvas.create_window(950, 300, window=label7)

        my_window.mainloop()  # enter main loop