public override void Update(GameTime gameTime) { if (settingBoardState == SettingBoardState.Showing) { settingBoardState = SettingBoardState.Show; } else if (settingBoardState == SettingBoardState.Show) { if (startButton.StartButtonClicked) { for (int i = 0; i < 2; i++) { PlayerSettings.Player[i].Type = PlayerType[i]; if (PlayerType[i] == PlayerTypes.AI) { PlayerSettings.Player[i].AIIndex = AIIndex[i]; } } settingBoardState = SettingBoardState.HidingForNewGame; } else if (startButton.ResumeButtonClicked) { settingBoardState = SettingBoardState.HidingForResume; } else { // 绘制选择状态 foreach (Piece piece in showPieces) { piece.CurrentDisplay = DisplayState.Normal; } foreach (Piece piece in playerTypePieces) { piece.CurrentDisplay = DisplayState.Normal; } foreach (int i in chooseIndex) { playerTypePieces[i].CurrentDisplay = DisplayState.CanMove; } for (int i = 0; i < AICount; i++) { if (chooseIndex[0] == 1) { aiTypePieces[0, i].PieceState = PieceState.Black; } else { aiTypePieces[0, i].PieceState = PieceState.Empty; } if (chooseIndex[1] == 2) { aiTypePieces[1, i].PieceState = PieceState.White; } else { aiTypePieces[1, i].PieceState = PieceState.Empty; } } if (chooseIndex[0] == 1) { aiTypePieces[0, AIIndex[0]].CurrentDisplay = DisplayState.WillReverse; } if (chooseIndex[1] == 2) { aiTypePieces[1, AIIndex[1]].CurrentDisplay = DisplayState.WillReverse; } if (curGame.IsActive) { // 获取鼠标状态 lastMouseState = currentMouseState; currentMouseState = Mouse.GetState(); ReversiPiecePosition tempPosition = Board.IsMouseInPiece(currentMouseState); // 如果移动鼠标 if (tempPosition != null) { // 如果划过的是黑白子 if (tempPosition.Y == 2) { if (tempPosition.X == 3) { showPieces[0].CurrentDisplay = DisplayState.WillMove; } else if (tempPosition.X == 4) { showPieces[1].CurrentDisplay = DisplayState.WillMove; } } // 如果划过的是玩家类型选择 else if (tempPosition.Y == 3) { int index = -1; if (tempPosition.X == 1) { index = 0; } else if (tempPosition.X == 2) { index = 1; } else if (tempPosition.X == 5) { index = 2; } else if (tempPosition.X == 6) { index = 3; } if (index >= 0) { playerTypePieces[index].CurrentDisplay = DisplayState.WillMove; } } // 如果划过的是AI类型 if ((tempPosition.X == 0 || tempPosition.X == 7) && (tempPosition.Y >= 3 && tempPosition.Y <= 2 + AICount)) { if (chooseIndex[0] == 1 && tempPosition.X == 0) { int index = tempPosition.Y - 3; aiTypePieces[0, index].CurrentDisplay = DisplayState.WillMove; } if (chooseIndex[1] == 2 && tempPosition.X == 7) { int index = tempPosition.Y - 3; aiTypePieces[1, index].CurrentDisplay = DisplayState.WillMove; } } // 如果按下鼠标左键 if ((currentMouseState.LeftButton == ButtonState.Pressed) && (lastMouseState.LeftButton == ButtonState.Released)) { // 如果点击的是黑白子 if (tempPosition.Y == 2) { if (tempPosition.X == 3) { chooseIndex[0] = 0; PlayerType[0] = PlayerTypes.Human; chooseIndex[1] = 2; PlayerType[1] = PlayerTypes.AI; } else if (tempPosition.X == 4) { chooseIndex[0] = 1; PlayerType[0] = PlayerTypes.AI; chooseIndex[1] = 3; PlayerType[1] = PlayerTypes.Human; } } // 如果点击的是玩家类型选择 else if (tempPosition.Y == 3) { if (tempPosition.X == 1) { chooseIndex[0] = 0; PlayerType[0] = PlayerTypes.Human; } if (tempPosition.X == 2) { chooseIndex[0] = 1; PlayerType[0] = PlayerTypes.AI; } if (tempPosition.X == 5) { chooseIndex[1] = 2; PlayerType[1] = PlayerTypes.AI; } if (tempPosition.X == 6) { chooseIndex[1] = 3; PlayerType[1] = PlayerTypes.Human; } } // 如果点击的是AI类型选择 if (tempPosition.X == 0 || tempPosition.X == 7) { if (chooseIndex[0] == 1 && tempPosition.X == 0) { AIIndex[0] = tempPosition.Y - 3; } if (chooseIndex[1] == 2 && tempPosition.X == 7) { AIIndex[1] = tempPosition.Y - 3; } } } } } foreach (Piece piece in showPieces) { piece.Update(gameTime); } foreach (Piece piece in playerTypePieces) { piece.Update(gameTime); } foreach (Piece piece in aiTypePieces) { piece.Update(gameTime); } startButton.Update(gameTime); } // 获取键盘状态 lastKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(Keys.Escape); // 当按下 Escape 键时 if (currentKeyboardState.IsKeyUp(Keys.Escape) && lastKeyboardState.IsKeyDown(Keys.Escape)) { if (settingType == SettingType.Pause) { settingBoardState = SettingBoardState.HidingForResume; } } } else if (settingBoardState == SettingBoardState.HidingForNewGame) { // TODO: 隐藏动画 settingBoardState = SettingBoardState.HideForNewGame; } else if (settingBoardState == SettingBoardState.HidingForResume) { // TODO: 隐藏动画 settingBoardState = SettingBoardState.HideForResume; } else if (settingBoardState == SettingBoardState.HideForNewGame) { curGame.State = GameState.StartLoad; } else if (settingBoardState == SettingBoardState.HideForResume) { curGame.State = GameState.InGame; } // base.Update(gameTime); }
public void Show(SettingType st) { settingType = st; startButton.Initialize(settingType); settingBoardState = SettingBoardState.Showing; }