예제 #1
0
        public void Start()
        {
            // Clear Game Console
            ConsoleManager.Cleaner.ClearConsole();

            // Show Game Logo
            ConsoleManager.Writer.PrintLogo();

            try
            {
                // Ask Questions
                var questionAnswers = ConsoleManager.QuestionAction.GetUserAnswers();

                // Player Init/Creation
                Player = GameFactory.PlayerFactory.CreatePlayer(questionAnswers[0].Answer.Split(": ")[0],
                                                                questionAnswers[1].Answer.Split(": ")[0],
                                                                (GenderType)Enum.Parse(typeof(GenderType), questionAnswers[2].Answer.Split(": ")[0]),
                                                                (Birthplaces)Enum.Parse(typeof(Birthplaces),
                                                                                        questionAnswers[3].Answer.Split("]")[0].Replace(" ", "")), Generator);
            }
            catch (NullReferenceException)
            {
                SupressException(Exceptions.Models.Exceptions.AnswerRequirementsFailed);
            }
            catch (ArgumentException)
            {
                SupressException(Exceptions.Models.Exceptions.InvalidInput);
            }
            catch (CustomException e)
            {
                SupressException(e.Message);
            }

            // Update GameTime
            GameTime = DateTime.Now;

            // Update Player's Progress to NewBorn
            PlayerProgress = PlayerProgress.NewBorn;
            ConsoleManager.UserInteraction.AddAction(
                $"You are born as {Player.FirstName} {Player.LastName} in {Player.GetBirthplace()}.");
            ConsoleManager.UserInteraction.AddAction(
                $"Your Father is {Player.Father.FirstName} {Player.Father.LastName}");
            ConsoleManager.UserInteraction.AddAction(
                $"Your Mother is {Player.Mother.FirstName} {Player.Mother.LastName}");

            // Clears Console
            ConsoleManager.Cleaner.ClearConsole();

            while (true)
            {
                // Print Logo
                ConsoleManager.Writer.PrintLogo();

                // Show User's HUD
                UserStatus.WriteStatus(Player);

                // Show what the user has done, last X (ActionLogNumber) actions
                UserStatus.WriteActionLog(ConsoleManager.UserInteraction.ActionLog, ActionLogNumber);

                // Show User's available options
                MenuManager.MenuLauncher.PrintMenu(PlayerProgress, MenuManager.OptionsContainer);

                if (EndTheGame)
                {
                    break;
                }

                try
                {
                    var commandAsString = ConsoleManager.Reader.ReadLine();

                    if (string.Equals(commandAsString, TerminationCommand, StringComparison.CurrentCultureIgnoreCase))
                    {
                        break;
                    }

                    CommandParser.ProcessCommand(commandAsString);
                }
                catch (Exception ex)
                {
                    // Just for now to debug, will be changed later on.
                    //ConsoleManager.UserInteraction.AddAction("An unexpected error has occured and has been logged.");
                    ConsoleManager.UserInteraction.AddAction(ex.Message);

                    Logger.GetLogger.Error(ex.Message);
                }

                // Clear Console
                ConsoleManager.Cleaner.ClearConsole();
            }

            // End Game Screen
            ConsoleManager.Cleaner.ClearConsole();

            ConsoleManager.Writer.PrintLogo();

            ConsoleManager.Writer.WriteLine(Player.ToString());

            ConsoleManager.Writer.WriteLine(
                $"Thank you for playing LifeSim Alpha {Assembly.GetExecutingAssembly().GetName().Version}");
        }