Creating Assignment June 5th(Quest of Elements).

For this assignment, the 2 random words were: Game and motif. I created a board game called Quest of Elements.

The “Quest of the Elements” game is an interactive text-based adventure implemented in Python. In the game, the player assumes the role of a character who embarks on a quest through different locations to acquire elemental powers. At the beginning of the game, the player selects a character class from a list of options, each with unique attributes such as health, attack, and defense. The player’s objective is to navigate through various locations on the game board, including difficult terrain, ancient ruins, and battles with dangerous creatures.

When encountering a location, the player is presented with a description and a chance to perform an action. The success of the action depends on a predetermined success chance. Successful actions lead to progress, while unsuccessful ones result in health loss.

In battles with creatures, the player engages in turn-based combat, strategically choosing attack and defense options. Both the player and enemy have health, attack, and defense attributes, and the battle continues until either party’s health reaches zero.

Throughout the game, the player’s health is constantly monitored, and reaching zero health leads to the game being over. However, defeating enemies grants the player powers, adding a layer of excitement.

The game provides options to continue playing or quit after each encounter.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  4 16:35:46 2023

@author: enockmecheo
"""

import random

# Define the player classes
player_classes = {
    "Knight": {
        "health": 100,
        "attack": 20,
        "defense": 15,
    },
    "Mage": {
        "health": 80,
        "attack": 30,
        "defense": 10,
    },
    "Rogue": {
        "health": 70,
        "attack": 25,
        "defense": 5,
    },
    "Druid": {
        "health": 90,
        "attack": 15,
        "defense": 20,
    },
}

# Define the game board
game_board = {
    "Terrain": {
        "description": "You navigate through difficult terrain.",
        "success_chance": 0.8,
        "health_loss": 5,
    },
    "Ruins": {
        "description": "You explore ancient ruins for clues.",
        "success_chance": 0.6,
        "health_loss": 10,
    },
    "Dangers": {
        "description": "You face dangerous creatures in battle.",
        "success_chance": 0.4,
        "health_loss": 15,
    },
}

# Define the elements
elements = ["Fire", "Water", "Earth", "Air"]

# Define the main game loop
def play_game():
    player_class = select_player_class()
    print("You are a", player_class)

    player_stats = player_classes[player_class]
    player_health = player_stats["health"]
    player_attack = player_stats["attack"]
    player_defense = player_stats["defense"]
    player_elements = []

    while True:
        print("\n---------")
        location = select_location()
        print("You encountered", location)

        location_stats = game_board[location]
        location_description = location_stats["description"]
        success_chance = location_stats["success_chance"]
        health_loss = location_stats["health_loss"]

        print(location_description)
        success = perform_action(success_chance)
        
        if success:
            if location == "Dangers":
                player_health, enemy_defense = battle(player_health, player_attack, player_defense)
                if player_health <= 0:
                    print("Game Over. You were defeated!")
                    break
                elif enemy_defense <= 0:
                    player_elements.append(random.choice(elements))
                    print("You defeated the enemy and acquired an element!")
            else:
                player_health -= health_loss
                print("You successfully completed the action but lost", health_loss, "health.")
        else:
            player_health -= health_loss
            print("You failed to complete the action and lost", health_loss, "health.")

        if player_health <= 0:
            print("Game Over. Your health reached 0!")
            break

        play_again = input("Do you want to continue? (y/n): ")
        if play_again.lower() != "y":
            break

    print("\n---------")
    print("Game Over. Thanks for playing!")

def select_player_class():
    print("Select your player class:")
    for i, player_class in enumerate(player_classes):
        print(i+1, "-", player_class)
    while True:
        choice = int(input("Enter the number of your choice: "))
        if 1 <= choice <= len(player_classes):
            return list(player_classes.keys())[choice-1]
        else:
            print("Invalid choice. Try again.")

def select_location():
    return random.choice(list(game_board.keys()))

def perform_action(success_chance):
    return random.random() <= success_chance

def battle(player_health, player_attack, player_defense):
    enemy_health = random.randint(50, 100)
    enemy_attack = random.randint(10, 20)
    enemy_defense = random.randint(5, 15)

    print("Battle Begins! You vs Enemy")
    print("Player Health:", player_health)
    print("Enemy Health:", enemy_health)

    while True:
        player_damage = player_attack - enemy_defense
        enemy_damage = enemy_attack - player_defense

        player_health -= enemy_damage
        enemy_health -= player_damage

        print("\nPlayer deals", player_damage, "damage to the enemy.")
        print("Enemy deals", enemy_damage, "damage to the player.")
        print("Player Health:", player_health)
        print("Enemy Health:", enemy_health)

        if player_health <= 0 or enemy_health <= 0:
            break

    return player_health, enemy_defense

# Start the game
play_game()

Leave a Reply

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