public void endTurnEvent(object sender, EventArgs e) { System.Console.WriteLine(GM.playersTurn + " has ended their turn."); //check if a player has won if (GM.checkWinningMoves()) { displayMessage(getColor(GM.playersTurn).ToString() + " wins!", GM.playersTurn); System.Windows.Forms.MessageBox.Show(getColor(GM.playersTurn).ToString() + " is the winna winna chicken dinna!"); // @todo End game and return to initial menu Application.Exit(); return; } //if game is not over GM.nextPlayersTurn(); reset1 = reset2 = null; made_move = false; //if the new player is an AI, take the turn if (GM.playerIsHuman[(int)GM.playersTurn - 2] == false) { displayMessage(getColor(GM.playersTurn).ToString() + " is thinking...", GM.playersTurn); Move move = GM.MakeNPCMove(); GM.gameBoard.setSpace(move.End.Item1, move.End.Item2, move.Player); GM.gameBoard.setSpace(move.Start.Item1, move.Start.Item2, Space.Empty); getPieceObjectByPosition(move.End.Item1, move.End.Item2).setPieceColor(getColor(move.Player)); getPieceObjectByPosition(move.Start.Item1, move.Start.Item2).setPieceColor(getColor(Space.Empty)); mainForm.ActiveForm.Refresh(); if(waitTime > 0) System.Threading.Thread.Sleep(waitTime); endTurnEvent(this, null); } else { displayMessage(getColor(GM.playersTurn).ToString() + "'s turn", GM.playersTurn); //System.Windows.Forms.MessageBox.Show(GM.getPreviousPlayersTurn() + "'s turn is over. Next turn goes to: " + GM.getPlayersTurn()); } }
// Swapping the new position with the old position. public void resetTurnEvent(object sender, EventArgs e) { if(reset1 != null && reset2 != null) { //Swapping the piece color Color temp = reset2.getPieceColor(); reset2.setPieceColor(reset1.getPieceColor()); reset1.setPieceColor(temp); //Moving the pieces on the board GM.gameBoard.setSpace(reset2.getPosition()[0], reset2.getPosition()[1], GM.gameBoard.getSpace(reset1.getPosition()[0], reset1.getPosition()[1])); // GM.gameBoard.setSpace(piece.getPosition()[0], piece.getPosition()[1], playingPieceTurn); GM.gameBoard.setSpace(reset1.getPosition()[0], reset1.getPosition()[1], Space.Empty); reset1 = null; reset2 = null; clearAllHighlighting(); made_move = false; return; } else { System.Console.WriteLine("Nothing to undo"); } }
void pieceClicked(object sender, EventArgs e) { if (made_move) { System.Console.WriteLine("You have already made a move"); return; } pieceObject piece = (pieceObject)sender; Space playingPieceTurn = GM.gameBoard.getSpace(piece.getPosition()[0], piece.getPosition()[1]); System.Console.WriteLine("This piece belongs to: " + playingPieceTurn); if (GM.playersTurn != playingPieceTurn && piece.getPieceColor() != Color.Gray) { System.Windows.Forms.MessageBox.Show("It's " + GM.getPlayersTurn() + "'s turn."); return; //System.Windows.Forms.MessageBox.Show("Its not your turn"); } if (piece.highlighted) { System.Console.WriteLine("You have selected a highlighted piece."); //Swapping the piece color Color temp = piece.getPieceColor(); piece.setPieceColor(hold.getPieceColor()); hold.setPieceColor(temp); //Moving the pieces on the board GM.gameBoard.setSpace(piece.getPosition()[0], piece.getPosition()[1], GM.gameBoard.getSpace(hold.getPosition()[0], hold.getPosition()[1])); // GM.gameBoard.setSpace(piece.getPosition()[0], piece.getPosition()[1], playingPieceTurn); GM.gameBoard.setSpace(hold.getPosition()[0], hold.getPosition()[1], Space.Empty); reset1 = piece; reset2 = hold; clearAllHighlighting(); made_move = true; return; } clearAllHighlighting(); hold = piece; System.Console.WriteLine("Position: " + piece.Location + "Color: " + piece.BackColor); int[] p = piece.getPosition(); System.Console.WriteLine("Position Array: " + p[0] + ", " + p[1]); List<Tuple<int, int>> moves = GM.gameBoard.getMoves(p[0], p[1]); foreach (Tuple<int, int> m in moves) { System.Console.WriteLine(m + " is a legal move"); pieceObject legalPiece = getPieceObjectByPosition(m.Item1, m.Item2); legalPiece.highlight(); System.Console.WriteLine("Space: " + GM.gameBoard.getSpace(p[0], p[1])); } }
public void InitializePieceControls() { int width = 15; int del = 3; int ystart = 50; int xstart = ystart + 4 * width; for (int i = 0; i < 17; i++) { for (int j = 0; j < 17; j++) { if (Board.isSpace(i, j)) { Space sp = GM.gameBoard.getSpace(i, j); int xPos = getXFromIndex(i, j, width, xstart, ystart); int yPos = getYFromIndex(i, j, width, xstart, ystart); pieceObject piece = new pieceObject(getColor(sp), i, j); piece.Click += pieceClicked; piece.Size = new System.Drawing.Size(20, 20); piece.Location = new System.Drawing.Point(xPos - del, yPos - del); piece.BackColor = getColor(sp); this.Controls.Add(piece); all_pieces[count] = piece; count++; } } } this.FormBorderStyle = FormBorderStyle.FixedSingle; // Make the gui non resizable. System.Console.WriteLine("There are " + count + " pieces"); //count = 0; }