public void PieceClicked(int x, int y) { //If a winning play has already been made, don't do anything. if (WinningPlay != null) { return; } GamePiece clickedSpace = Board[x, y]; //The piece must "fall" to the lowest unoccupied space in the clicked column if (clickedSpace.Color == PieceColor.Blank) { while (y < 5) { GamePiece nextSpace = Board[x, y + 1]; y = y + 1; if (nextSpace.Color == PieceColor.Blank) { clickedSpace = nextSpace; } } clickedSpace.Color = CurrentTurn; } //After every move, check to see if that move was a winning move. WinningPlay = GetWinner(); if (WinningPlay == null) { SwitchTurns(); } }
private WinningPlay GetWinner() { WinningPlay winningPlay = null; for (int i = 0; i < 7; i++) { for (int j = 0; j < 6; j++) { winningPlay = EvaluatePieceForWinner(i, j, EvaluationDirection.Up); if (winningPlay != null) { return(winningPlay); } winningPlay = EvaluatePieceForWinner(i, j, EvaluationDirection.UpRight); if (winningPlay != null) { return(winningPlay); } winningPlay = EvaluatePieceForWinner(i, j, EvaluationDirection.Right); if (winningPlay != null) { return(winningPlay); } winningPlay = EvaluatePieceForWinner(i, j, EvaluationDirection.DownRight); if (winningPlay != null) { return(winningPlay); } } } return(winningPlay); }
public void Reset() { Board = new GamePiece[7, 6]; //Populate the Board with blank pieces for (int i = 0; i <= 6; i++) { for (int j = 0; j <= 5; j++) { Board[i, j] = new GamePiece(PieceColor.Blank); } } CurrentTurn = PieceColor.Red; WinningPlay = null; }