Пример #1
0
        /// <summary>
        /// Gets the values from the user, the creates the player.
        /// </summary>
        public void CreatePlayer()
        {
            _view.DisplayClear(); //  Blank screen

            //  Get name
            _view.DisplayMessage("What is your name?");
            string name = _view.GetUserInput();

            //  Echo inputs
            _view.DisplayMessage(string.Format("Your name is {0}", name));
            _view.WaitForAnyKey();

            _view.DisplayClear(); //  Blank screen

            //  Get gender
            _view.DisplayMessage("Are you MALE or FEMALE?");
            bool validGender = false;
            Character.Genders gender = Character.Genders.MALE;
            //  Loop until a valid input
            while (!validGender)
            {
                if (Enum.TryParse<Character.Genders>(_view.GetUserInput(), true, out gender))
                {
                    validGender = true;
                }
                else
                {
                    _view.DisplayMessage("That was not a valid gender, try again.");
                }
            }

            //  Echo inputs
            _view.DisplayMessage(string.Format("Your name is {0}", name));
            _view.DisplayMessage(string.Format("You are {0}", gender.ToString()), false);
            _view.WaitForAnyKey();

            _view.DisplayClear(); //  Blank screen

            _view.DisplayMessage("What is your race?");
            foreach (Character.Races r in Enum.GetValues(typeof(Character.Races)))
            {
                _view.DisplayMessage(r.ToString(), false);
            }
            bool validRace = false;
            Character.Races race = Character.Races.HUMAN;
            while (!validRace)
            {
                if (Enum.TryParse<Character.Races>(_view.GetUserInput(), true, out race))
                {
                    validRace = true;
                }
                else
                {
                    _view.DisplayMessage("That was not a valid race, try again.");
                }
            }

            //  Echo inputs
            _view.DisplayMessage(string.Format("Your name is {0}", name));
            _view.DisplayMessage(string.Format("You are {0}", gender.ToString()), false);

            //  Make a into an for grammar reasons.
            string aSuffix = "";
            if (race.ToString() == "ELF")
            {
                aSuffix = "n";
            }

            _view.DisplayMessage(string.Format("You are a{0} {1}", aSuffix, race.ToString()), false);
            _view.WaitForAnyKey();

            //  Create the player
            _player = new Player(name, "You are the Player", gender, race);
        }
Пример #2
0
 /// <summary>
 /// Creates the reference to the player for the ConsoleView
 /// </summary>
 /// <param name="player"></param>
 public void InitializePlayerReference(Player player)
 {
     _myPlayer = player;
 }