vendredi 2 avril 2021

How to save these randomly generated items

Quick story; I've been learning C# the past few months and decided to make a simple little ASCII-RPG game to implement new skills as I learn them. I'm currently trying to implement a mechanic that will allow a random village to be generated and then added as an input-able option on the "map". So basically whatever iteration you initially generate for the village would be saved and added to the "map" and then allow the user to return to it rather than simply generate a new village iteration, if that makes sense.

ex.

class Program
{
    Villages randVillages = new Villages();
    public static void Main()
    {
        bool exitMap = false;
        while (exitMap == false)
        {
            Console.WriteLine("This is your map");
            Console.WriteLine();
            Console.WriteLine("1) Search for a new location");

            string newLocation = Console.ReadLine();
            Console.Clear();

            if (newLocation == "1")
            {
                {
                    Villages.StandardVillage();
                }
            }
            if (newLocation == "2")
            {
                exitMap = true;
            }
        }
    }
}

//

class Villages
{
    public static void StandardVillage()
    {
        int setLandscape;
        Random randVillage = new Random();
        setLandscape = randVillage.Next(1, 5);

        if (setLandscape == 1)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("       (________________)");
            Console.WriteLine("        |              |");
            Console.WriteLine("        |  []  []  []  |");
            Console.WriteLine(" _______|____          |");
            Console.WriteLine(" |          |  []  []  |       ");
            Console.WriteLine(" | { }  { } |          |    _I_____");
            Console.WriteLine(" |          |  []  []  |   /_______\\");
            Console.WriteLine(" | { }  { } |          |   | [] [] |");
            Console.WriteLine("_|          |  []  []  |___| [] [] |_");
            Console.WriteLine("-----------------------------------------");
        }
        if (setLandscape == 2)
        {
            Console.WriteLine();
            Console.WriteLine("               xXxXxXxXxXxXx ");
            Console.WriteLine("               |           | ");
            Console.WriteLine("               | |}{| |}{| | ");
            Console.WriteLine(" ____________  |           | ");
            Console.WriteLine(" |          |  | |}{| |}{| |     _I_____");
            Console.WriteLine(" |  []  []  |  |           |    /_______\\");
            Console.WriteLine(" |          |  | |}{| |}{| |  _ | [] [] |");
            Console.WriteLine("_|  []  []  |__|           |__|_| [] [] |_");
            Console.WriteLine("----------------------------------------------");
        }
        if (setLandscape == 3)
        {
            Console.WriteLine();
            Console.WriteLine("                {_{_{_{_}_}_}_}");
            Console.WriteLine("                /             \\");
            Console.WriteLine("               /_______________\\");
            Console.WriteLine("   _I_____     |               |");
            Console.WriteLine("  /_______\\    |  {} {} {} {}  |");
            Console.WriteLine("  | [] [] |    |               |  (__)");
            Console.WriteLine("xX| [] [] |Xx__|  {} {} {} {}  |___()_");
            Console.WriteLine("------------------------------------------");
        }
        if (setLandscape == 4)
        {
            Console.WriteLine();
            Console.WriteLine("                     {____________}");
            Console.WriteLine("                     |            |");
            Console.WriteLine(" __________________  | [}{]  [}{] |");
            Console.WriteLine(" |                |  |            |");
            Console.WriteLine(" | [] [] [] [] [] |  | [}{]  [}{] | ____");
            Console.WriteLine(" |                |  |            | |__|");
            Console.WriteLine("_| [] [] [] [] [] |__| [}{]  [}{] |_|  |");
            Console.WriteLine("--------------------------------------------");
        }

        int setTool1;
        setTool1 = randVillage.Next(1, 3);

        if (setTool1 == 1)
        {
            Console.WriteLine("1) Speak to someone in charge");
        }
        if (setTool1 == 2)
        {
            Console.WriteLine("1) Ask about local rumors");
        }

        int setTool2;
        setTool2 = randVillage.Next(1, 3);
            
        if (setTool2 == 1)
        {
            Console.WriteLine("2) Go to the local guild hall");
        }
        if (setTool2 == 2)
        {
            Console.WriteLine("2) Go to the local tavern");
        }
        Console.WriteLine("0) Exit to map");

        string villageOptions = Console.ReadLine();
        Console.Clear();

        if (villageOptions == "1" && setTool1 == 1)
        {
            Console.WriteLine("The elderman of the village greets you cheerily.");
        }
        if (villageOptions == "1" && setTool1 == 2)
        {
            Console.WriteLine("A local indulges you.");
            Console.WriteLine("\"I hear the local tavern cooks a mean birdpie.\"");
        }
        if (villageOptions == "2" && setTool2 == 1)
        {
            Console.WriteLine("You approach the local guild hall. The sign on the building reads:");
            Console.WriteLine("\"Fang-jitsu Guild\"");
        }
        if (villageOptions == "2" && setTool2 ==2)
        {
            Console.WriteLine("You approach the local tavern, the taste of whiskey already on ");
            Console.WriteLine("your lips.");
        }
        if (villageOptions == "0")
        {
            Program.Main();
        }

        Console.ReadLine();
        Console.Clear();
    }
}



Aucun commentaire:

Enregistrer un commentaire