/// <summary>
        /// Call this from Game.Update(). Updates keyboard and mouse states, updates all phases, then erases phases scheduled for elimination, and updates toasts and FPS counter.
        /// </summary>
        /// <param name="gameTime">gameTime parameter from the Game.Update() method.</param>
        public static void Update(GameTime gameTime)
        {
            Keyboard_OldState = Keyboard_NewState;
            Mouse_OldState    = Mouse_NewState;
            Keyboard_NewState = Keyboard.GetState();
            Mouse_NewState    = Mouse.GetState();

            WasMouseLeftClick   = Mouse_NewState.LeftButton == ButtonState.Released && Mouse_OldState.LeftButton == ButtonState.Pressed;
            WasMouseMiddleClick = Mouse_NewState.MiddleButton == ButtonState.Released && Mouse_OldState.MiddleButton == ButtonState.Pressed;
            WasMouseRightClick  = Mouse_NewState.RightButton == ButtonState.Released && Mouse_OldState.RightButton == ButtonState.Pressed;


            float elapsedSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            inFpsCounter.UpdateCycle();
            if (Root.PhaseStack.Count > 0)
            {
                Root.PhaseStack.Peek().Update(Root.inGame, (float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            SecondsSinceStart   += elapsedSeconds;
            SecondsSinceStartInt = (int)SecondsSinceStart;

            for (int i = Root.PhaseStack.Count - 1; i >= 0; i--)
            {
                GamePhase ph = Root.PhaseStack[i];
                if (ph.ScheduledForElimination)
                {
                    Root.PhaseStack.RemoveAt(i);
                }
            }

            Root.updateToasts(elapsedSeconds);
        }
Esempio n. 2
0
        void button_Click(Button obj)
        {
            MessageBoxResult msgResult = MessageBoxResult.Cancel;

            if (obj.Caption == "OK")
            {
                msgResult = MessageBoxResult.OK;
            }
            if (obj.Caption == "Cancel")
            {
                msgResult = MessageBoxResult.Cancel;
            }
            if (obj.Caption == "Yes")
            {
                msgResult = MessageBoxResult.Yes;
            }
            if (obj.Caption == "No")
            {
                msgResult = MessageBoxResult.No;
            }

            if (Root.PhaseStack.Count > 1)
            {
                GamePhase gp = Root.PhaseStack[Root.PhaseStack.Count - 2];
                gp.ReturnedMessageBoxResult   = msgResult;
                Root.ReturnedMessageBoxResult = msgResult;
            }
            Root.PopFromPhase();
        }
        void button_Click(Button obj)
        {
            MessageBoxResult msgResult = MessageBoxResult.Cancel;

            if (obj.Caption == "OK")
            {
                msgResult = MessageBoxResult.OK;
            }
            if (obj.Caption == "Cancel")
            {
                msgResult = MessageBoxResult.Cancel;
            }
            if (obj.Caption == "Yes")
            {
                msgResult = MessageBoxResult.Yes;
            }
            if (obj.Caption == "No")
            {
                msgResult = MessageBoxResult.No;
            }

            if (Root.PhaseStack.Count > 1)
            {
                GamePhase gp = Root.PhaseStack[Root.PhaseStack.Count - 2];
                gp.ReturnedMessageBoxResult   = msgResult;
                Root.ReturnedMessageBoxResult = msgResult;
            }

            Root.PopFromPhase();
            if (msgResult == MessageBoxResult.OK || msgResult == MessageBoxResult.Yes)
            {
                WhatWithNewName?.Invoke(textbox?.Text);
            }
        }
        /// <summary>
        /// Calls the "Destruct" method of the phase, which should, by default, set the ScheduledForElimination flag.
        /// The phase will be popped from stack only later, not immediately.
        /// </summary>
        public static void PopFromPhase()
        {
            GamePhase gp = PhaseStack.Peek();

            if (gp != null)
            {
                gp.Destruct(inGame);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Draws all phases on the stack using the Root spritebatch, in stack order.
        /// </summary>
        /// <param name="gameTime">gameTime parameter from the Game.Draw() method.</param>
        public static void DrawPhase(GameTime gameTime)
        {
            for (var index = 0; index < PhaseStack.Count; index++)
            {
                GamePhase gp = PhaseStack[index];
                if (index == PhaseStack.Count - 1)
                {
                    Root.BeforeLastDraw?.Invoke();
                }

                gp.Draw(Root.inSpriteBatch, Root.inGame, (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
        }
 /// <summary>
 /// Adds new game on top of the stack and initializes it.
 /// </summary>
 /// <param name="phase">The phase to put on stack.</param>
 public static void PushPhase(GamePhase phase)
 {
     CurrentPhase = phase;
     phase.Initialize(inGame);
 }