private Boolean MakeMove(XNAGameBoardPostion selectedSquare) { GamePieceMove move = new GamePieceMove(selectedPiece, selectedSquare.GameBoardSpace.X, selectedSquare.GameBoardSpace.Y); gameBoard.ApplyMove(move); if(move.IsJump) if(gameBoard.IsThereASecondJump(move)) return false; return true; }
private void HandleTurnForHumanPlayer(PlayerColours currentPlayerColour, XNAGameBoardPostion selectedPoint) { switch (gameState) { case GameStates.Playing: GetSelectedPiece(selectedPoint); if(selectedPiece!=null) if (gameBoard.IsMovablePieceSelected(selectedPiece, currentPlayerColour)) { HighLightPossibleMoves(selectedPiece, currentPlayerColour); gameState = GameStates.PieceSelected; } break; case GameStates.PieceSelected: if (IsNextClickAMove()) { if (MakeMove(selectedPoint)) CompleteCurrentTurn(currentPlayerColour); else gameState = GameStates.NextJump; } else { UnSelectPiece(); gameState = GameStates.Playing; } break; case GameStates.NextJump: if (IsNextClickAMove()) { if (MakeMove(selectedPoint)) CompleteCurrentTurn(currentPlayerColour); } break; } HandleAdditionalJumps(currentPlayerColour); }
private void GetSelectedPiece(XNAGameBoardPostion selectedSquare) { if (gameBoard.IsPieceInThisSquare(selectedSquare.GameBoardSpace.X, selectedSquare.GameBoardSpace.Y)) selectedPiece = gameBoard.GameBoardSpaces[selectedSquare.GameBoardSpace.X, selectedSquare.GameBoardSpace.Y]; }
private void HandleAdditionalJumps(PlayerColours colour) { if (gameState == GameStates.NextJump) { Point jumpAbleSquare = new Point(selectedPiece.HorizontalPostion, selectedPiece.VerticalPostion); XNAGameBoardPostion selectedSquare = new XNAGameBoardPostion(jumpAbleSquare); HighLightPossibleJumps(selectedPiece, colour); } }
protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (gameType == GameType.OnePlayer && gameTurn == PlayerTurn.BlackTurn) { System.Threading.Thread.Sleep(1000); HandleBlackTurnForAIPlayer(); } while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gameState == GameStates.TitleScreen) HandleScreenTouch(gesture); else if (gameState == GameStates.SelectDifficultyScreen) HandleScreenTouch(gesture); else if (gameState != GameStates.GameOver) { selectedPoint = GetTouchLocation(gesture); if (gameTurn == PlayerTurn.WhiteTurn) HandleTurnForHumanPlayer(PlayerColours.White, selectedPoint); else if (gameType == GameType.TwoPlayer && gameTurn == PlayerTurn.BlackTurn) HandleTurnForHumanPlayer(PlayerColours.Black, selectedPoint); } else ResetGame(); } base.Update(gameTime); }