Пример #1
0
        private bool IsLastFrame(BaseGameFrame frame)
        {
            var attrs = frame.GetType().GetCustomAttributes(typeof(GameFrameAttribute), true);

            foreach (var attr in attrs)
            {
                if (((GameFrameAttribute)attr).IsLastFrame)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Starts the game! Uses whatever screen is currently configured
        /// </summary>
        /// <param name="new_character"></param>
        public void Run(bool new_character = false)
        {
            BaseGameFrame current_frame = null;

            var character = GameManager.Get <ICharacter>();

            if (!character.IsInitialized || new_character || character.Count() < 1)
            {
                logger.Info("No valid character was found or new character parameter was true. Requesting new character be created");
                character     = GameManager.NewCharacter();
                current_frame = this.FindFirstFrame();
            }
            else
            {
                var last_decision = character.OrderBy(x => x.DecisionHistoryOrder).Last();
                current_frame = this.Frames[last_decision.ChosenFrame];
            }

            var screen = GameManager.Get <IScreen>();

            while (true)
            {
                var opt = screen.GetDecision(current_frame);

                if (this.IsLastFrame(current_frame))
                {
                    logger.InfoFormat("Game ended because current frame is set as last frame - {0}", current_frame.ID);
                    break;
                }

                current_frame.MakeDecision(opt, character);

                if (opt == GameLoop.ExitOptionCode)
                {
                    logger.Info("Screen requested exit");
                    break;
                }

                if (opt == GameLoop.GotoExitFrameOptionCode)
                {
                    logger.Info("Screen requested go to last frame");

                    var f = this.Frames.Values.FirstOrDefault(x => this.IsLastFrame(x));

                    if (f == null)
                    {
                        logger.Info("No last frame found. Exiting");
                        break;
                    }

                    current_frame = f;
                    continue;
                }

                if (opt == GameLoop.NewGameOptionCode)
                {
                    logger.Info("Screen requested new game");
                    character     = GameManager.NewCharacter();
                    current_frame = this.FindFirstFrame();
                    continue;
                }

                if (opt == GameLoop.SaveOverCharacterOptionCode)
                {
                    logger.Info("Screen requested save over character. Frame not advanced this loop");
                    GameManager.SaveCurrentCharacter(false);
                    continue;
                }

                if (opt == GameLoop.SaveOverCharacterOptionCode)
                {
                    logger.Info("Screen requested save character with backup. Frame not advanced this loop");
                    GameManager.SaveCurrentCharacter();
                    continue;
                }

                if (!current_frame.Choices.ContainsKey(opt))
                {
                    logger.InfoFormat("Game ended because no option could be found with ID {0}", opt);
                    break;
                }

                var next_id = current_frame.Choices[opt].NextFrameID;

                if (!this.Frames.ContainsKey(next_id))
                {
                    logger.InfoFormat("Game ended because no frame could be found with ID {0}", next_id);
                    break;
                }

                current_frame = this.Frames[current_frame.Choices[opt].NextFrameID];

                character.StoreDecision(current_frame.ID);
            }

            GameManager.Quit();
        }