示例#1
0
        public GameState Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            KeyboardState kbState = Keyboard.GetState();

            lastState    = currentState;
            currentState = Mouse.GetState();

            // Current Position of the mouse-cursor
            Point p = new Point(currentState.X, currentState.Y);

            // Hover-Check-Routine for the Button(s)
            if (bl[0].ClickTangle.Contains(new Point(currentState.X, currentState.Y)))
            {
                bl[0].Texture = backArrow_select;
            }
            else
            {
                bl[0].Texture = backArrow;
            }

            // Starts to run down the Highscore if the Timer is active
            if (Timer.Running == true)
            {
                if (Timer.GetScore() > 0.0)
                {
                    // Use timer to determine the Score
                    Timer.Score -= gameTime.ElapsedGameTime.TotalMilliseconds / 60;
                }
            }

            /// <summary>
            /// Ends the Game if the score hits 0 while gaming
            /// </summary>
            if (Timer.Score == 0)
            {
                Thread.Sleep(200);
                Session.Gameover = true;
                return(GameState.Endgame);
            }

            /// <summary>
            /// Checks if the players have won the game (a.k.a. matched all possible pairs)
            /// </summary>
            if (Session.PairsUntilWin == 0)
            {
                Timer.StopTimer();

                Thread.Sleep(200);
                /// Implement optional winning-sound-playing here

                // Returns the Endgame state if the players have turned all cards correctly within the given time
                return(GameState.Endgame);
            }

            // Temporary solution to get to the highscores prematurely
            if (kbState.IsKeyDown(Keys.F))
            {
                return(GameState.Highscore);
            }

            // Temporary solution to get to the Success-Screen prematurely
            if (kbState.IsKeyDown(Keys.H))
            {
                Countdown.Initialize(10);
                return(GameState.Endgame);
            }

            /// <summary>
            /// Checks if the players paired up two cards of the same kind and runs the according logic
            /// </summary>
            if (Session.TurnedCards.Count == 2)
            {
                Thread.Sleep(200);
                if (Session.TurnedCards[0].MotiveID == Session.TurnedCards[1].MotiveID)
                {
                    cardList[Session.TurnedCards[0].Id].CurrentTexture = correct;
                    cardList[Session.TurnedCards[1].Id].CurrentTexture = correct;
                    Session.ResetTurnedCards();
                    Session.PairsUntilWin--;
                    Thread.Sleep(200);
                }
                else
                {
                    cardList[Session.TurnedCards[0].Id].CurrentTexture = backside;
                    cardList[Session.TurnedCards[1].Id].CurrentTexture = backside;
                    Session.ResetTurnedCards();
                    Thread.Sleep(200);
                }
            }

            // Click-Check-Routine
            if (currentState.LeftButton == ButtonState.Released && lastState.LeftButton == ButtonState.Pressed)
            {
                // Button to return to MainMenu-Screen
                if (bl[0].ClickTangle.Contains(new Point(currentState.X, currentState.Y)))
                {
                    Extension.PlaySoundEffect("menuClick");
                    g.Clear(Color.Black);
                    Thread.Sleep(20);
                    return(GameState.MainMenuSession);
                }

                Thread.Sleep(20);
                int index = 0;
                foreach (Card c in cardList)
                {
                    if (c.Zone.Contains(p))
                    {
                        Extension.PlaySoundEffect("cardFlip");
                        // Performs a check if a card is already turned before running the Gamelogic for turning
                        if (c.CurrentTexture != correct)
                        {
                            switch (Session.TurnedCards.Count)
                            {
                            case 0:
                            {
                                c.CurrentTexture = LoadTextureByMotive(c.MotiveID);
                                c.Id             = index;
                                Session.TurnedCards.Add(c);
                                Thread.Sleep(20);
                                break;
                            }

                            case 1:
                            {
                                if (c.Id != Session.TurnedCards[0].Id)
                                {
                                    c.CurrentTexture = LoadTextureByMotive(c.MotiveID);
                                    c.Id             = index;
                                    Session.TurnedCards.Add(c);
                                    Thread.Sleep(20);
                                    break;
                                }
                                else
                                {
                                    index--;
                                    break;
                                }
                            }
                            }
                        }
                    }
                    index++;
                }
            }

            // Hover-Implementation to test Card-Zoning
            foreach (Card c in cardList)
            {
                if (c.Zone.Contains(p))
                {
                    GameSpecs.CurrentCard = c.MotiveID;
                }
            }

            // Button-Press to Pause the Game
            if (kbState.IsKeyDown(Keys.Escape))
            {
                Thread.Sleep(100);
                return(GameState.MainMenuSession);
            }

            else
            {
                return(GameState.Running);
            }
        }