示例#1
0
        public override void HandleInput(InputState input)
        {
            String Message = "";
            if (input == null)
                throw new ArgumentNullException("input");
            int playerIndex = (int)ControllingPlayer.Value;
            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];

            if (input.IsPauseGame(ControllingPlayer))
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else if (Player_1_Points >= mySettings.ScoreToWin)
            {
                AudioManager.PlayCue("Music_Win");
                if (!mySettings.QuickPlay)
                {
                    //Update Player Information
                    myPlayers.myPlayers[0].Won();
                    myPlayers.myPlayers[1].Lost();
                    myPlayersXML.Save(myPlayers);
                    Message = myPlayers.myPlayers[0].UserName + " Win!";
                    //Update Game History
                    Class_Library.Game myGame = new Class_Library.Game();
                    myGame.GameID = myGameList.GetLastID() + 1;
                    myGame.Player1_Name = myPlayers.myPlayers[0].UserName;
                    myGame.Player2_Name = myPlayers.myPlayers[1].UserName;
                    myGame.Player1_Score = Player_1_Points;
                    myGame.Player2_Score = Player_2_Points;
                    myGameList.AddItem(myGame);
                    myGameHistoryXML.Save(myGameList);

                    //New Code Added
                    myLatestSave.Player1_Name = myPlayers.myPlayers[0].UserName;
                    myLatestSave.Player2_Name = myPlayers.myPlayers[1].UserName;

                    myLatestSave.Player1_Score = Player_1_Points;
                    myLatestSave.Player2_Score = Player_2_Points;
                    myLatestSave.BallSpeed_X = BallPosition.XSpeedFactor;
                    myLatestSave.BallSpeed_Y = BallPosition.YSpeedFactor;
                    mySaveGameXML.Save(myLatestSave);
                }
                else
                {
                    Message = "Artificial Intelligence Beat you. Too Bad";
                }

                MessageBoxScreen WinningMessageBox = new MessageBoxScreen(Message, false);
                WinningMessageBox.Accepted += WinningMessageBoxAccepted;
                ScreenManager.AddScreen(WinningMessageBox, ControllingPlayer);
            }
            else if (Player_2_Points >= mySettings.ScoreToWin)
            {
                AudioManager.PlayCue("Music_Win");
                if (!mySettings.QuickPlay)
                {
                    TimeSpan GameDuration = new TimeSpan();
                    GameDuration = DateTime.Now - myGameTime;

                    myPlayers.myPlayers[0].Lost();
                    myPlayers.myPlayers[1].Won();
                    myPlayersXML.Save(myPlayers);
                    Message = myPlayers.myPlayers[1].UserName + " Win!";

                    Class_Library.Game myGame = new Class_Library.Game();
                    myGame.GameID = myGameList.GetLastID() +1;
                    myGame.Player1_Name = myPlayers.myPlayers[0].UserName;
                    myGame.Player2_Name = myPlayers.myPlayers[1].UserName;
                    myGame.Player1_Score = Player_1_Points;
                    myGame.Player2_Score = Player_2_Points;
                    myGame.TimeDuration = Convert.ToInt32(GameDuration.TotalSeconds);
                    myGameList.AddItem(myGame);
                    myGameHistoryXML.Save(myGameList);

                    //New Code Added
                    myLatestSave.Player1_Name = myPlayers.myPlayers[0].UserName;
                    myLatestSave.Player2_Name = myPlayers.myPlayers[1].UserName;

                    myLatestSave.Player1_Score = Player_1_Points;
                    myLatestSave.Player2_Score = Player_2_Points;
                    myLatestSave.BallSpeed_X = BallPosition.XSpeedFactor;
                    myLatestSave.BallSpeed_Y = BallPosition.YSpeedFactor;
                    mySaveGameXML.Save(myLatestSave);
                }
                else
                {
                    Message = "Congratulations, you Beat the Computer";
                }

                MessageBoxScreen WinningMessageBox = new MessageBoxScreen(Message, false);
                WinningMessageBox.Accepted += WinningMessageBoxAccepted;
                ScreenManager.AddScreen(WinningMessageBox, ControllingPlayer);
            }
            else
            {
                //determine how fast the paddle will move
                if (keyboardState.IsKeyDown(Keys.Up))
                    RightPaddlePosition.MoveDown();
                if (keyboardState.IsKeyDown(Keys.Down))
                    RightPaddlePosition.MoveUp();

                if (mySettings.QuickPlay)
                {
                    int temp = (int)BallPosition.YSpeedFactor;
                    if (temp > 5)
                        temp = 5;
                    LeftPaddlePosition.movefactor = temp;

                    if (BallPosition.Y > LeftPaddlePosition.Y)
                        LeftPaddlePosition.MoveUp();
                    else if (BallPosition.Y < LeftPaddlePosition.Y)
                        LeftPaddlePosition.MoveDown();
                }
                else
                {
                    if (keyboardState.IsKeyDown(Keys.W))
                        LeftPaddlePosition.MoveDown();
                    if (keyboardState.IsKeyDown(Keys.S))
                        LeftPaddlePosition.MoveUp();
                }
            }
        }
示例#2
0
文件: MenuScreen.cs 项目: kanhar/xna
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                AudioManager.PlayCue("Menu_Accept");
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                AudioManager.PlayCue("Menu_Accept");
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
示例#3
0
文件: GameScreen.cs 项目: kanhar/xna
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
 }
示例#4
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }