Coder Social home page Coder Social logo

balthizar01 / highsail-text-rpg Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 31 KB

A side project for the HighSail Studios team that are in intro programming courses. This project is to help learn and understand core programming concepts.

C# 100.00%

highsail-text-rpg's People

Contributors

balthizar01 avatar thefool309 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

thefool309

highsail-text-rpg's Issues

Load Character

The "Load Game" option on the menu should list the characters that are located in the "characters.json" file. The code should read the file, use JSON.NET by Newtonsoft (add the dependency) to reserialize the JSON, and then list each JSON object (character) to the player with a number attached. The number is for the player to choose which character to load.

Update Player Class

Updates should include:

  • pClass property for character class
  • Attributes (Strength, Agility, Endurance, Intellect)
  • Mana
  • Experience
  • Race

Combat System

We need someone to start working on a combat system. The implementation should be fairly simple. The class will pretty much just be interacting with the Player and whatever Enemy object is passed into it. Here is a sample implementation I've made, feel free to edit or create something new:

public class CombatSystem
{
    private Player player;
    private Enemy enemy;

    public CombatSystem(Player player, Enemy enemy)
    {
        this.player = player;
        this.enemy = enemy;
    }

    public void StartCombat()
    {
        Console.WriteLine("Combat has started!");

        // Main combat loop
        while (player.IsAlive && enemy.IsAlive)
        {
            // Player's turn
            Console.WriteLine("\nPlayer's turn:");
            if (PlayerTurn())
            {
                Console.WriteLine("Player successfully fled the battle!");
                return; // Exit combat if player flees
            }

            if (!enemy.IsAlive) break; // Check if enemy was defeated

            // Enemy's turn
            Console.WriteLine("\nEnemy's turn:");
            EnemyTurn();

            if (!player.IsAlive) break; // Check if player was defeated
        }

        // Determine outcome
        if (!player.IsAlive)
        {
            Console.WriteLine("Player has been defeated.");
        }
        else if (!enemy.IsAlive)
        {
            Console.WriteLine("Enemy has been defeated.");
        }
    }

    private bool PlayerTurn()
    {
        // For simplicity, only two actions: attack and flee.
        Console.WriteLine("Choose an action:\n1. Attack\n2. Flee");
        string choice = Console.ReadLine();

        if (choice == "1")
        {
            player.Attack(enemy);
            return false; // Did not flee
        }
        else if (choice == "2")
        {
            if (player.TryFlee())
            {
                return true; // Successfully fled
            }
            else
            {
                Console.WriteLine("Failed to flee!");
                return false; // Failed to flee
            }
        }

        return false;
    }

    private void EnemyTurn()
    {
        enemy.Attack(player);
    }
}

Calling it would look like this:

Player player = new Player { Name = "Hero", Health = 100, AttackPower = 15, FleeChance = 0.3 };
Enemy enemy = new Enemy { Name = "Goblin", Health = 50, AttackPower = 10 };

CombatSystem combat = new CombatSystem(player, enemy);
combat.StartCombat();

The Player and Enemy objects are just example objects, but the CombatSystem object is accurate.

Character Creator

The character creator should provide the player with options to fill out some of the character information such as:

  • Name
  • Class
  • Race

The new character should be saved into a file called "characters.json" into a folder called "textRPG". The folder should be located in C:\Users<currentuser>\Documents\

Run logic checks to see if the file or folder exists first. If not, they should be created and THEN save the character.

NPC Database

Just like the Enemy database, we need an NPC database as well. These are NPCs that you'd find in town, merchants along the roads, or any other entity that generally is not considered naturally hostile.

{
  "NPC_ID": 1,
  "name": "Arthur Pendragon",
  "spawnTown": "Camelot",
  "spawnChance": 100,
  "lootTable": [
    {"item": "Gold Coin", "dropChance": 50},
    {"item": "Rusty Sword", "dropChance": 5}
  ]
}

Dialogue Manager/Database

This one might be a bit more complex or might not be, all depends on how we implement this. However, the repository for dialogue will be in a single JSON file with the following structure:

{
  "NPC_ID": 1,
  "Dialogues": [
    {
      "ID": "smith_greeting",
      "Text": "Welcome to my smithy, adventurer!",
      "Responses": [
        {
          "Text": "Show me your wares.",
          "NextDialogueID": "smith_shop"
        },
        {
          "Text": "Heard any rumors?",
          "NextDialogueID": "smith_rumors"
        },
        {
          "Text": "Goodbye.",
          "NextDialogueID": null
        }
      ]
    },
    {
      "ID": "smith_shop",
      "Text": "Here's what I've got for sale.",
      "Responses": []
    },
    {
      "ID": "smith_rumors",
      "Text": "They say the old well is haunted...",
      "Responses": [
        {
          "Text": "Tell me more.",
          "NextDialogueID": "smith_well_story"
        },
        {
          "Text": "I should go.",
          "NextDialogueID": null
        }
      ]
    }
  ]
}

With this structure and how the NPC model/database is structured, it should be easy to create and use a DialogueManager and map the NPC_ID from the NPC Database to the NPC_ID in the Dialogue Database.

This example shows the usage of the NPC_ID to map out their dialogue options, as well as fields to use for easy navigation into the next line of the dialogue tree. It also gives responses that are available for the player to choose from.

Enemy Database

We can have a single JSON file that contains all the enemies in the game as JSON objects that can be called whenever needed. Sample JSON would look like this:

{
  "enemyID": 1,
  "name": "Goblin",
  "spawnArea": "Forest",
  "spawnChance": 25,
  "lootTable": [
    {"item": "Gold Coin", "dropChance": 50},
    {"item": "Rusty Sword", "dropChance": 5}
  ]
}

With this we'd be able to have the player encounter enemies on a % chance based on the area they're in and what the spawn chance of the enemy is.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.