Coder Social home page Coder Social logo

balthizar01 / highsail-text-rpg Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.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 Issues

Inventory and Player Inventory

An Inventory class needs to be created.

The inventory itself should be a Dictionary<TKey, TValue> of objects. Make sure it is a dictionary and not an array due to arrays being unable to be resized at will. The TKey for each slot in the inventory should be a number and the TValue will be the object. So essentially the dictionary should be declared using Dictionary<int, object> pInventory = new Dictionary<int, object>

The class should contain methods to do the following:

  • View inventory
  • View Item
  • Add items
  • Remove items
  • Use items
  • Equip items

View Inventory
This method should display all the items in the players inventory in a numbered list with the number being the TKey from the dictionary.

View Item
This method should display the information about that chosen item. The method will have a (int playerChoice) parameter which will be used to pull the matching TKey from the dictionary and display the available information from the object associated with that TKey.

Add Items
The method will be simple. It will take in an object parameter which will be added to the end of the dictionary and given a TKey of the last entries TKey + 1. So if there are 5 items in the dictionary and the last entry's TKey = 5, then the next TKey should be 6 and so on.

Remove Items
Self explanatory but has a catch. This method will have a base and an overload. The base should just take in an object parameter that will be used to find the match in the dictionary and remove it. Normally you'd take the TKey but since the way that the object will be removed can't dictate the TKey before the TValue, we'll have to search for the TValue instead and then remove the pair once a match has been found. The overloaded version should take in an (int playerChoice) parameter which will be used to identify the TKey being removed.

Use Items
This one will be a bit unique. It will take in a (int playerChoice) parameter to dictate which TKey is being used but it also needs to identify if the object matched with the chosen TKey is usable. For now, that's all it needs to do until we decide if we're going to create separate functionality to use an item, or if the item will be used directly from this method.

Equip Items
This method will do exactly as its name suggests. It will take in a (int playerChoice) parameter and find the matching TKey in the dictionary. We then need to check if the object for that TKey can be equipped. The object will have field of (bool canEquip) which can be used to check if can be equipped. If true, then it needs to use the object field that denotes which slot it can be equipped in and insert it into the dictionary for the players equipped items. A check must be made first to see if that slot is empty and if it is not empty, then the object that is currently equipped needs to go into the inventory slot of the item that is being equipped. Otherwise, just add the item to the equipped items and remove it from the inventory dictionary.

UPDATE: I DO NOT EXPECT ALL OF THESE METHODS TO BE COMPLETE. I just want the base code done and it will be worked on as other parts of the system are finished.

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.

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.

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.

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

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.

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}
  ]
}

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.