Пример #1
0
        public static Player PlayerCreateOrLoad()
        {
            // Class object to store player information along with variables used for varification.
            Player oldUser = new Player("name", "pw", "class", "race", 0, 0, 0, 0, 0, 0, 0, false);
            string userInput;
            string userName;
            string password;
            bool   exit = false;

            // Program will continue until the user creates a profile or loads a profile
            while (exit == false)
            {
                Console.WriteLine("\nCreate Account or Load Account");
                Console.WriteLine("Type 'Create' or 'Load' to make a new character or load a character");
                Console.Write(" > ");
                userInput = Console.ReadLine();

                // Here the users input is used as validation for what the program needs to do, either create or load. In this case its for creation.
                if (userInput.ToLower() == "create")
                {
                    oldUser = PlayerCreation.CreatePlayer(oldUser);
                    return(oldUser);
                }
                // Here that same user input is used to load a character.
                else if (userInput.ToLower() == "load")
                {
                    // The program takes the player's User Name and passes it to a new class method to see if it is valid.
                    Console.Write("\nPlease enter User Name: > ");

                    userName = Console.ReadLine();
                    oldUser  = LoadPlayerFromFile.LoadPlayer(userName);

                    // Here if the players user name is valid it will then ask the user for their password, and as long as their password is correct the program will move on
                    if (File.Exists($"{userName}.csv"))
                    {
                        while (exit == false)
                        {
                            Console.Write("\nPlease Enter your Password: > ");
                            password = Console.ReadLine();

                            if (password == oldUser.Password)
                            {
                                return(oldUser);
                            }
                            else
                            {
                                Console.WriteLine("\nIncorrect Password!\n");
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nInvalid Input! Please type create or load!\n");
                }
            }
            return(oldUser);
        }
Пример #2
0
        public static Player CreatePlayer(Player newPlayer)
        {
            // variables and objects for validation and player creation.
            string password   = null;
            string name       = null;
            bool   validName  = false;
            bool   validClass = false;
            bool   validRace  = false;

            // Continues to run until the user has made a user name that is not in use. To keep previous users data safe.
            #region User Name Creation
            while (validName == false)
            {
                Console.Write("\nPlease create a User Name! > ");
                name = Console.ReadLine();

                // After the user enters their name the if statement checks to see if the file name exits. If it doesn't then the program will continue.
                if (!File.Exists($"{name}.csv"))
                {
                    newPlayer.PlayerName = name;
                    validName            = true;
                }
                else
                {
                    Console.WriteLine("\nUser Name already Exists!\n");
                }
            }

            #endregion

            // Continues to run until the user meets all requirements allocated for a password.
            #region Password Creation
            while (password == null || !password.Any(char.IsLower) || !password.Any(char.IsUpper) || !password.Any(x => char.IsLetterOrDigit(x)))
            {
                Console.WriteLine("\nMake a Password. Must have 1 captical letter, 1 lowercase letter, and 1 special character.");
                Console.Write("Please create a Password! > ");

                // Takes users Entry and passes it to a method for validation. Method will only return once user has a valid password, which will then exit the loop.
                password = PasswordValidator(Console.ReadLine());
            }
            newPlayer.Password = password;
            #endregion Password Creation

            // Continues to run until the user chooses a class that we have allocated in our enums.
            #region Class Options
            while (validClass == false)
            {
                Console.WriteLine("Pick Class. Choose Warrior, Mage, Rogue, Paladin");
                Console.Write("Choose a class!  > ");
                // Created the class method to make sure that the users entry matches our enum.
                string playerClass = FirstLetterToCap.MakeFirstLetterCap(Console.ReadLine());

                // This accesses our enum class and converts data inside to a string so that we can use our enums as comparision to user's entry.
                if (playerClass == Classes.Warrior.ToString() || playerClass == Classes.Mage.ToString() || playerClass == Classes.Rogue.ToString() || playerClass == Classes.Paladin.ToString())
                {
                    // After the class is chosen, the player gets stats based off class chosen.
                    newPlayer.PlayerClass = playerClass;
                    switch (playerClass)
                    {
                    case "Warrior":
                        newPlayer.PlayerLevel = 1;
                        newPlayer.CurrentRoom = GameAttributes.rooms[0];
                        newPlayer.Equipment   = GameAttributes.PlayerWeaponByID(201);
                        newPlayer.PlayerMaxHP = 100;
                        newPlayer.HP          = 30;
                        newPlayer.AC          = 13;
                        newPlayer.Gold        = 50;
                        newPlayer.XP          = 125;
                        newPlayer.IsDead      = false;
                        break;

                    case "Mage":
                        newPlayer.PlayerLevel = 1;
                        newPlayer.CurrentRoom = GameAttributes.rooms[0];
                        newPlayer.Equipment   = GameAttributes.PlayerWeaponByID(202);
                        newPlayer.PlayerMaxHP = 90;
                        newPlayer.HP          = 30;
                        newPlayer.AC          = 14;
                        newPlayer.Gold        = 100;
                        newPlayer.XP          = 175;
                        newPlayer.IsDead      = false;
                        break;

                    case "Rogue":
                        newPlayer.PlayerLevel = 1;
                        newPlayer.CurrentRoom = GameAttributes.rooms[0];
                        newPlayer.Equipment   = GameAttributes.PlayerWeaponByID(203);
                        newPlayer.PlayerMaxHP = 80;
                        newPlayer.HP          = 30;
                        newPlayer.AC          = 15;
                        newPlayer.Gold        = 75;
                        newPlayer.XP          = 150;
                        newPlayer.IsDead      = false;
                        break;

                    case "Paladin":
                        newPlayer.PlayerLevel = 1;
                        newPlayer.CurrentRoom = GameAttributes.rooms[0];
                        newPlayer.Equipment   = GameAttributes.PlayerWeaponByID(204);
                        newPlayer.PlayerMaxHP = 110;
                        newPlayer.HP          = 30;
                        newPlayer.AC          = 13;
                        newPlayer.Gold        = 25;
                        newPlayer.XP          = 100;
                        newPlayer.IsDead      = false;
                        break;

                    default:
                        Console.WriteLine("Invalid input");
                        break;
                    }
                    validClass = true;
                }
                else
                {
                    Console.WriteLine("\nNot a valid Class!\n");
                }
            }
            #endregion Class Options

            // Continues to run until the user chooses a race that we have allocated in our enums.
            #region Race Options
            while (validRace == false)
            {
                Console.WriteLine("Pick Race. Choose Elf, Human, Dwarf, Orc");
                Console.Write("Choose a Race!  > ");
                // Created the class method to make sure that the users entry matches our enum.
                string playerRace = FirstLetterToCap.MakeFirstLetterCap(Console.ReadLine());

                // This accesses our enum race and converts data inside to a string so that we can use our enums as comparision to user's entry.
                if (playerRace == Race.Elf.ToString() || playerRace == Race.Human.ToString() || playerRace == Race.Dwarf.ToString() || playerRace == Race.Orc.ToString())
                {
                    newPlayer.PlayerRace = playerRace;
                    validRace            = true;
                }
                else
                {
                    Console.WriteLine("\nNot a valid Class!\n");
                }
            }
            #endregion Race Options


            // After all player creations requirements are met the object is passed to another class to save the data to a CSV file.
            PlayerToFile.SavePlayerData(newPlayer);
            // Them the player must login to their new account.
            Console.Write("\nPlease enter your User Name to start: > ");
            return(newPlayer = LoadPlayerFromFile.LoadPlayer(Console.ReadLine()));
        }
Пример #3
0
        public static void RunCombat(Player player, string noun)
        {
            bool exit = false;
            int  playerDamage;
            int  mobDamage;
            Mob  mob = player.CurrentRoom.CurrentMob;

            // Keeps the do while going as long as the mob/player hasn't died.
            do
            {
                if (player.CurrentRoom.CurrentMob != null)
                {
                    if (noun == mob.Name.ToLower())
                    {
                        // Checks to make sure the mob isn't dead
                        if (mob.IsDead == false)
                        {
                            // Rolls the players attack
                            Console.ForegroundColor = ConsoleColor.Green;
                            int playerAttack = RandomNumGenerator.NumberBetween(1, 20);
                            Console.WriteLine($"You attack with a {player.Equipment.Name} and roll a {playerAttack}");

                            if (playerAttack >= mob.AC)
                            {
                                playerDamage = RollDice.PlayerDiceRoll(player);

                                Console.WriteLine($"You hit {mob.Name} for {playerDamage} damage!");
                                mob.HP -= playerDamage;
                                Console.WriteLine($"The {mob.Name} has {mob.HP} HP!");
                                // Once mob dies all items are automatically given to player //TODO add a display of what the player gained (xp, gold, items, etc)
                                if (mob.HP <= 0)
                                {
                                    Console.ForegroundColor = ConsoleColor.Cyan;
                                    CombatResults(player, mob);
                                    exit = true;
                                    Console.ForegroundColor = ConsoleColor.White;
                                }
                            }
                            else
                            {
                                Console.WriteLine("You Missed!!!");
                            }
                            Console.ForegroundColor = ConsoleColor.Red;

                            // Mobs turn to attack if it is still alive, rolls the mobs attacks and continues combat until the player or mob dies
                            if (mob.IsDead == false)
                            {
                                int monsterAttack = RandomNumGenerator.NumberBetween(1, 20);

                                if (monsterAttack > player.AC)
                                {
                                    mobDamage = RollDice.MonsterDiceRoll(mob);

                                    Console.WriteLine($"The {mob.Name} attacks and rolls a {monsterAttack}");
                                    Console.WriteLine($"The {mob.Name} hits for {mobDamage} damage!");
                                    player.HP -= mobDamage;
                                    Console.WriteLine($"The {player.PlayerName} has {player.HP} HP!");
                                    if (player.HP < 0)
                                    {
                                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                                        Console.WriteLine("You have died!");
                                        LoadPlayerFromFile.LoadPlayer(player.PlayerName);
                                        exit = true;
                                        Console.ForegroundColor = ConsoleColor.White;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine($"The {mob.Name} Missed!");
                                }
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Magenta;
                                Console.WriteLine($"You have won!");
                                exit = true;
                            }

                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine($"Press enter to continue!");
                            Console.ReadLine();
                        }
                        else
                        {
                            Console.WriteLine($"The monster is dead");
                            exit = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine($"You do not see a {noun}");
                        exit = true;
                    }
                }
                else
                {
                    Console.WriteLine("There is nothing to attack here.");
                    exit = true;
                }
            } while (exit == false);
        }