Example #1
0
        // Will be used to start the game in the main function
        public static void Run()
        {
            UserInput userMessage = new UserInput("");
            UserInput userInt     = new UserInput(0);
            string    message;

            FileSetup.PlayerFileRead(ref player, ref npc, playerFile, itemFile);
            if (monsters.Length <= 0)
            {
                FileSetup.MonsterFileWrite(ref monsters, monsterFile);
            }
            FileSetup.MonsterFileRead(ref monsters, monsterFile);
            player.name  = userMessage.GetUserMessage("What is your name? ");
            player.age   = userInt.GetUserInt("How old are you? ");
            player.level = FileSetup.LevelRead(levelFile);

            bool run = true;

            // Infinite loop used to make it so the game keeps running
            while (run)
            {
                Console.Clear();
                Console.Write("What would you like to do? Explore or visit the shop? ");
                message = Console.ReadLine().ToLower();
                // Used to give the user some options
                switch (message)
                {
                case "explore":
                    Console.Clear();
                    MonsterExplore();
                    if (player.health <= 0)
                    {
                        Console.WriteLine("You have died. The program will now close.");
                        Thread.Sleep(2500);
                        run = false;
                    }
                    break;

                case "shop":
                    Console.Clear();
                    Shop();
                    break;

                default:
                    break;
                }
            }
        }
Example #2
0
        // User will use this to explore the monster
        public static void MonsterExplore()
        {
            Random random = new Random();

            Monster[] tempArrayMonster = new Monster[monsters.Length];
            int       i     = 0;
            int       count = 0;

            Tools.
            Shuffle(ref player.storage);
            Tools.ShuffleDamage(ref player);
            foreach (Item item in player.storage)
            {
                if (item == null)
                {
                    count++;
                }
                else
                {
                    if (item.itemType != ItemType.WEAPON)
                    {
                        count++;
                    }
                }
            }
            if (count < player.storage.Length)
            {
                bool monsterActive = false;
                foreach (Monster monster in monsters)
                {
                    if (monster != null && monster.level <= player.level)
                    {
                        tempArrayMonster[i] = monster;
                        monsterActive       = true;
                    }
                    i++;
                }
                // Checks if the monster is exists
                if (monsterActive)
                {
                    int num     = random.Next() % tempArrayMonster.Length;
                    int counter = 0;
                    foreach (Monster monster in tempArrayMonster)
                    {
                        if (monster != null && monster.level <= player.level)
                        {
                            break;
                        }
                        counter++;
                    }
                    // Turns the monster to null if it matches the tempMonstersName
                    try
                    {
                        Monster tempMonster     = tempArrayMonster[counter];
                        string  tempMonsterName = tempMonster.name;
                        if (tempMonster != null)
                        {
                            Action.FightScene(ref tempMonster, ref player);
                        }
                        for (int x = 0; x < monsters.Length; x++)
                        {
                            if (monsters[x] != null)
                            {
                                if (monsters[x].name == tempMonsterName)
                                {
                                    monsters[x] = null;
                                }
                            }
                        }
                        Tools.Shuffle(ref monsters);
                        FileSetup.MonsterFileWrite(ref monsters, monsterFile);
                        FileSetup.LevelWrite(levelFile, ref player);
                    }
                    catch (NullReferenceException e)
                    {
                        Console.WriteLine($"Hello, {player.name} we could not find a monster to kill. Please try again. ");
                        Thread.Sleep(2500);
                    }
                }
                else
                {
                    Console.WriteLine($"Hello, {player.name} we could not find a monster to kill. Please try again. ");
                    Thread.Sleep(2500);
                }
            }
            else
            {
                Console.WriteLine($"Hello, {player.name} you currently don't have any items that you can adventure with.");
                Thread.Sleep(2500);
            }
        }