Pirate Island Adventure

Overview

Pirate Island Adventure is a text-based action-adventure game created in Python with a graphical user interface (GUI) built using tkinter. In this game, players take on the role of a pirate stranded on a mysterious island. To survive and find the legendary treasure, players must explore the island, battle monkeys, solve riddles, and manage their resources. This project demonstrates both my coding and design skills, with a strong focus on interactive gameplay and narrative elements.

Gameplay

In Pirate Island Adventure, players must explore locations like the jungle, different beach areas, and a secluded hut to uncover clues that lead to hidden treasure. Along the way, they encounter wild monkeys, who present combat challenges, and coconut trees, which provide resources to help them survive.

Key Features

  1. Exploration and Navigation
    The island has multiple locations to explore, each with unique encounters or hidden clues.Code Snippet: Moving Between Locations
def move():
    global location
    new_location = location_var.get()
    location = new_location
    display_text(f"You move to the {location}.")
    
    # Encounter events based on location
    if location in ["Jungle", "South Side of the Beach", "West Side of the Beach"]:
        random_event()
    elif location in ["East Beach", "Hut", "Deep Jungle"]:
        find_clue(location)

Here, move() handles player navigation, updating the location variable and triggering events like encounters or clue discoveries based on the player’s location.

Combat System
Players encounter hostile monkeys in some locations. They can engage in combat using a sword or blunderbuss, each with different attack properties.

Code Snippet: Combat Mechanics

def fight_monkey():
    global player_health
    monkey_health = 30
    combat_text = f"Player Health: {player_health} | Monkey Health: {monkey_health}\n"
    
    while monkey_health > 0 and player_health > 0:
        weapon = weapon_var.get()
        if weapon == "Sword" and inventory.get("Sword"):
            damage = random.randint(5, 15)
            monkey_health -= damage
            combat_text += f"You slash the monkey with your sword for {damage} damage.\n"
        elif weapon == "Blunderbuss" and inventory.get("Blunderbuss") and inventory["Ammo"] > 0:
            damage = random.randint(20, 30)
            monkey_health -= damage
            inventory["Ammo"] -= 1
            combat_text += f"You fire your blunderbuss for {damage} damage.\n"
        else:
            combat_text += "Invalid weapon or out of ammo.\n"
            break

        # Monkey attacks if still alive
        if monkey_health > 0:
            monkey_damage = random.randint(5, 10)
            player_health -= monkey_damage
            combat_text += f"The monkey retaliates for {monkey_damage} damage.\n"

        # Check if player health is zero
        if player_health <= 0:
            display_text("You have been defeated by the monkeys! The game will restart.")
            initialize_game()
            return

    combat_text += "You have defeated the monkey!"
    display_text(combat_text)

The combat system uses turn-based logic, where the player and monkey exchange attacks until one’s health reaches zero. This snippet also shows the restart mechanic if the player loses.

Clue-Based Treasure Hunt
The player must follow a sequence of clues to progress through the game. Each clue is hidden in a specific location, with riddles guiding the player to the next location.

Code Snippet: Clue Discovery

def find_clue(area):
    if not clues_found[area]:
        clues_found[area] = True
        display_text(f"You find a clue in the {area}! It reads:\n'{clue_riddles[area]}'")
    else:
        display_text(f"You have already found the clue in the {area}.")

Each clue is associated with a specific location and is marked as found once the player discovers it. The find_cluefunction displays the clue’s riddle to direct the player to the next location.

Resource Management
Players can collect coconuts from trees, which restore health when used. This encourages players to manage resources carefully.

Code Snippet: Collecting and Using Coconuts

def shake_tree():
    global player_health
    inventory["Coconuts"] += 1
    update_coconut_display()
    display_text("You shake the tree and a coconut falls! You collect it for later use.")

def use_coconut():
    global player_health
    if inventory["Coconuts"] > 0:
        player_health = min(player_health + 20, 100)
        inventory["Coconuts"] -= 1
        update_coconut_display()
        display_text("You eat a coconut, restoring some health!")
    else:
        display_text("You have no coconuts to use.")

These functions allow players to collect coconuts, which are stored in an inventory and used to restore health, adding a strategic element to resource management.

Graphical User Interface (GUI)
The game features a GUI built with tkinter, including buttons for exploration, combat, and item usage.

Code Snippet: Setting up the Main GUI

# GUI Setup
window = tk.Tk()
window.title("Pirate Adventure Game")

# Display area for game text
output_text = tk.Text(window, wrap="word", height=15, width=50, state="disabled")
output_text.pack(pady=10)

# Coconut count display
coconut_count = tk.Label(window, text=f"Coconuts: {inventory['Coconuts']}")
coconut_count.pack()

# Move and Combat Buttons
location_var = tk.StringVar(value="Beach")
tk.Button(window, text="Move", command=move).pack(pady=10)
tk.Button(window, text="Use Coconut", command=use_coconut).pack(pady=10)

window.mainloop()
  1. This snippet shows the setup of a tkinter GUI for displaying text, showing inventory items, and adding interactivity for player actions.

Technical Highlights

  • Python & tkinter: Used for creating an interactive GUI and handling event-based gameplay.
  • Game Logic & Combat Mechanics: Turn-based combat system with health and weapon choices.
  • Inventory Management: Tracks player resources and health-restoring items.
  • Restart Mechanic: If health reaches zero, the game resets automatically.

Reflections

Working on Pirate Island Adventure allowed me to experiment with text-based interactive storytelling and explore complex logic in combat mechanics. The project required careful management of game state and events to create a challenging yet engaging experience. I look forward to expanding this project with additional features like puzzles and interactive environments in the future.

Screenshots

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *