// this procedure checks the target position to see whether the piece occupying it can be captured public virtual bool canCapture(Square targetPosition, Board gameBoard) { Piece.Piececolour colour = this.getColour(); PieceSet[] piecesets = gameBoard.getPieceSets(); if (colour == Piece.Piececolour.BLACK) { foreach (Piece piece in piecesets[1].getPieceSet()) { if (piece.getPosition() == targetPosition) { return(true); } } return(false); } else { foreach (Piece piece in piecesets[0].getPieceSet()) { if (piece.getPosition() == targetPosition) { return(true); } } return(false); } }
// sets the game object and populates it accordingly private void PlayButton_Click(object sender, EventArgs e) { Game game1; String gameStyle = "NULL"; Piece.Piececolour player1Colour = Piece.Piececolour.BLACK; //sets properties of game object depending on which game mode has been selected if (StandardGame.Checked == true) { game1 = new StandardGame(); if (ValidateSelection(ref player1Colour, ref gameStyle) == true) { game1.setGameType(Game.gameType.Standard); BoardAdmin.game1 = game1; BoardAdmin.gameStyle = gameStyle; BoardAdmin.player1Colour = player1Colour; gameBoardForm = new BoardUI(); gameBoardForm.Show(); } } else { if (MathsGame.Checked == true) { game1 = new MathsGame(); if (ValidateSelection(ref player1Colour, ref gameStyle) == true) { game1.setGameType(Game.gameType.Maths); game1.setTimerValue((int)timerValue.Value); BoardAdmin.game1 = game1; BoardAdmin.gameStyle = gameStyle; BoardAdmin.player1Colour = player1Colour; BoardAdmin.player1Diff = (int)Player1MathsDifficulty.Value; BoardAdmin.player2Diff = (int)Player2MathsDifficulty.Value; BoardUI gameBoardForm = new BoardUI(); gameBoardForm.Show(); } } if (NoMathsGame.Checked == true) { game1 = new TimedGame(); if (ValidateSelection(ref player1Colour, ref gameStyle) == true) { game1.setGameType(Game.gameType.Timed); game1.setTimerValue((int)timerValue.Value); BoardAdmin.game1 = game1; BoardAdmin.gameStyle = gameStyle; BoardAdmin.player1Colour = player1Colour; BoardUI gameBoardForm = new BoardUI(); gameBoardForm.Show(); } } if (MathsGame.Checked == false && NoMathsGame.Checked == false) { System.Windows.Forms.MessageBox.Show("Please select an Option for a maths game"); } } }
// creates the game by setting player colours and by creating th game board and setting it up with pieces public virtual void createGame(Piece.Piececolour player1colour, Piece.Piececolour player2colour) { player1.setPlayerColour(player1colour); player2.setPlayerColour(player2colour); gameBoard = new Board(); gameBoard.setUpBoard(player1colour); // white moves first in chess turn = Piece.Piececolour.WHITE; }
// makes sure that all the neccessary selections have been made private bool ValidateSelection(ref Piece.Piececolour player1Colour, ref String gameStyle) { if (Black.Checked == false && White.Checked == false) { System.Windows.Forms.MessageBox.Show("Please select an Option for Player1 Colour"); return(false); } else { if (Black.Checked == true) { player1Colour = Piece.Piececolour.BLACK; } else { player1Colour = Piece.Piececolour.WHITE; } } if (MarbleStyle.Checked == false && WoodStyle.Checked == false && PlainBlueStyle.Checked == false && PlainRedStyle.Checked == false && PlainPurpleStyle.Checked == false && PlainBrownStyle.Checked == false) { System.Windows.Forms.MessageBox.Show("Please select an Option for game board style"); return(false); } else { if (MarbleStyle.Checked == true) { gameStyle = "MARBLE"; } if (WoodStyle.Checked == true) { gameStyle = "WOOD"; } if (PlainBlueStyle.Checked == true) { gameStyle = "PLAINBLUE"; } if (PlainRedStyle.Checked == true) { gameStyle = "PLAINRED"; } if (PlainPurpleStyle.Checked == true) { gameStyle = "PLAINPURPLE"; } if (PlainBrownStyle.Checked == true) { gameStyle = "PLAINBROWN"; } } return(true); }
//sets up the board by creating two piecelists, initiallising those lists. //also initallising the square object array. public void setUpBoard(Piece.Piececolour player1colour) { //instantiates square objects for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { squares[j, k] = new Square(); } } PieceSet blackPieces = new PieceSet(); PieceSet whitePieces = new PieceSet(); // invokes methods which set all the properties if each piece blackPieces.setInitalPieceList(Piece.Piececolour.BLACK, squares, player1colour); whitePieces.setInitalPieceList(Piece.Piececolour.WHITE, squares, player1colour); pieceSets[0] = blackPieces; pieceSets[1] = whitePieces; //assigns the x and y co-ordinate properties to the squares of the board for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { squares[i, j].X = i; squares[i, j].Y = j; } } //sets the squares that the pieces are on, to occupied status foreach (Piece piece in blackPieces.getPieceSet()) { piece.getPosition().occ = true; } foreach (Piece piece in whitePieces.getPieceSet()) { piece.getPosition().occ = true; } }
public override void createGame(Piece.Piececolour player1colour, Piece.Piececolour player2colour) { base.createGame(player1colour, player2colour); }
public void setTurn(Piece.Piececolour TurnColour) { turn = TurnColour; }
public void setPlayerColour(Piece.Piececolour colour) { p_playercolour = colour; }
//initiallises all piece objects and fills up the corresponding piece list. public void setInitalPieceList(Piece.Piececolour piececolour, Square[,] squares, Piece.Piececolour player1colour) { int index; // the index of the pieces on the board (first row pieces - king, rook etc) int pawnindex; // pawns are in the second row, so have their own index setColour(piececolour); //creates all the piece objects neccessary Pawn[] Blackpawns = new Pawn[8]; Pawn[] Whitepawns = new Pawn[8]; Rook[] BlackRooks = new Rook[2]; Rook[] WhiteRooks = new Rook[2]; Bishop[] WhiteBishops = new Bishop[2]; Bishop[] BlackBishops = new Bishop[2]; Knight[] WhiteKnights = new Knight[2]; Knight[] BlackKnights = new Knight[2]; Queen WhiteQueen = new Queen(); King WhiteKing = new King(); Queen BlackQueen = new Queen(); King BlackKing = new King(); int i = 0; //Initiallise all piece objects for (int j = 0; j < 8; j++) { Blackpawns[j] = new Pawn(); Whitepawns[j] = new Pawn(); } for (int j = 0; j < 2; j++) { WhiteBishops[j] = new Bishop(); BlackBishops[j] = new Bishop(); } for (int j = 0; j < 2; j++) { BlackRooks[j] = new Rook(); WhiteRooks[j] = new Rook(); } for (int j = 0; j < 2; j++) { WhiteKnights[j] = new Knight(); BlackKnights[j] = new Knight(); } //fills up the list with the pieces and setting their properties if (colour == Piece.Piececolour.BLACK) { i = 0; // the x coordinate this can be reassigned as the pieces are populated //player 1 pieces needs to be at the bottom of the board so assign the indexes accordingly if (player1colour == Piece.Piececolour.BLACK) { index = 7; pawnindex = 6; } else { index = 0; pawnindex = 1; } // sets properties of pawns foreach (Pawn pawn in Blackpawns) { pawn.setType(Piece.pieceType.PAWN); pawn.setColour(Piece.Piececolour.BLACK); pawn.setImage(test_chess.Properties.Resources.Chess_pdt60); pawn.setPosition(squares[i, pawnindex]); if (player1colour == Piece.Piececolour.BLACK) { pawn.movedirection = -1; } else { pawn.movedirection = 1; } m_pieceSet.Add(pawn); i++; } i = 0; // x coordinate value // sets properties of rooks foreach (Rook rook in BlackRooks) { rook.setType(Piece.pieceType.ROOK); rook.setColour(Piece.Piececolour.BLACK); rook.setImage(test_chess.Properties.Resources.Chess_rdt60); rook.setPosition(squares[i, index]); m_pieceSet.Add(rook); i = 7; } i = 1;// x coordinate value foreach (Knight knight in BlackKnights) { knight.setType(Piece.pieceType.KNIGHT); knight.setColour(Piece.Piececolour.BLACK); knight.setImage(test_chess.Properties.Resources.Chess_ndt60); knight.setPosition(squares[i, index]); m_pieceSet.Add(knight); i = 6; } i = 2; // x coordinate value foreach (Bishop bishop in BlackBishops) { bishop.setType(Piece.pieceType.BISHOP); bishop.setColour(Piece.Piececolour.BLACK); bishop.setImage(test_chess.Properties.Resources.Chess_bdt60); bishop.setPosition(squares[i, index]); m_pieceSet.Add(bishop); i = 5; } BlackKing.setType(Piece.pieceType.KING); BlackKing.setColour(Piece.Piececolour.BLACK); BlackKing.setImage(test_chess.Properties.Resources.Chess_kdt60); BlackKing.setPosition(squares[3, index]); BlackQueen.setType(Piece.pieceType.QUEEN); BlackQueen.setColour(Piece.Piececolour.BLACK); BlackQueen.setImage(test_chess.Properties.Resources.Chess_qdt60); BlackQueen.setPosition(squares[4, index]); m_pieceSet.Add(BlackKing); m_pieceSet.Add(BlackQueen); } else { // otherwise player 1 is black and so black pieces must be at the bottom of the board if (player1colour == Piece.Piececolour.BLACK) { index = 0; pawnindex = 1; } else { index = 7; pawnindex = 6; } i = 0; foreach (Pawn pawn in Whitepawns) { pawn.setType(Piece.pieceType.PAWN); pawn.setColour(Piece.Piececolour.WHITE); pawn.setImage(test_chess.Properties.Resources.Chess_plt60); pawn.setPosition(squares[i, pawnindex]); if (player1colour == Piece.Piececolour.WHITE) { pawn.movedirection = -1; } else { pawn.movedirection = 1; } m_pieceSet.Add(pawn); i++; } i = 0; foreach (Rook rook in WhiteRooks) { rook.setType(Piece.pieceType.ROOK); rook.setColour(Piece.Piececolour.WHITE); rook.setImage(test_chess.Properties.Resources.Chess_rlt60); rook.setPosition(squares[i, index]); m_pieceSet.Add(rook); i = 7; } i = 2; foreach (Bishop bishop in WhiteBishops) { bishop.setType(Piece.pieceType.BISHOP); bishop.setColour(Piece.Piececolour.WHITE); bishop.setImage(test_chess.Properties.Resources.Chess_blt60); bishop.setPosition(squares[i, index]); m_pieceSet.Add(bishop); i = 5; } i = 1; foreach (Knight knight in WhiteKnights) { knight.setType(Piece.pieceType.KNIGHT); knight.setColour(Piece.Piececolour.WHITE); knight.setImage(test_chess.Properties.Resources.Chess_nlt60); knight.setPosition(squares[i, index]); m_pieceSet.Add(knight); i = 6; } WhiteKing.setType(Piece.pieceType.KING); WhiteKing.setColour(Piece.Piececolour.WHITE); WhiteKing.setImage(test_chess.Properties.Resources.Chess_klt60); WhiteKing.setPosition(squares[3, index]); WhiteQueen.setType(Piece.pieceType.QUEEN); WhiteQueen.setColour(Piece.Piececolour.WHITE); WhiteQueen.setImage(test_chess.Properties.Resources.Chess_qlt60); WhiteQueen.setPosition(squares[4, index]); m_pieceSet.Add(WhiteQueen); m_pieceSet.Add(WhiteKing); } }
private void setColour(Piece.Piececolour acolour) { colour = acolour; }