private void CheckWinner() { int centerX = board.LastPlaseNode.X; int centerY = board.LastPlaseNode.Y; int[] num = new int[8]; int i = 0; for (int xDir = -1; xDir <= 1; xDir++) { for (int yDir = -1; yDir <= 1; yDir++) { if (xDir == 0 && yDir == 0) { continue; } num[i] = CheckCount(centerX, centerY, xDir, yDir); i++; } } if ((num[0] + num[7]) > 5 || (num[1] + num[6]) > 5 || (num[2] + num[5]) > 5 || (num[3] + num[4]) > 5) { winner = currentPlayer; //winner = board.GetPiecesType(board.LastPlaseNode.X, board.LastPlaseNode.Y); } }
public Pieces PlacePieces(int x, int y, PiecesType type) { Point nodeId = findTheClosetNode(x, y); if (nodeId == NO_MATCH_NODE) { return(null); } if (pieces[nodeId.X, nodeId.Y] != null) { return(null); } Point formPos = convertToFormPosition(nodeId); if (type == PiecesType.BLACK) { pieces[nodeId.X, nodeId.Y] = new BlackPieces(formPos.X, formPos.Y); } else if (type == PiecesType.WHITE) { pieces[nodeId.X, nodeId.Y] = new WhitePieces(formPos.X, formPos.Y); } lastPlaceNode = nodeId; return(pieces[nodeId.X, nodeId.Y]); }
public Pieces PlacePieces(int x, int y) { Pieces pieces = board.PlacePieces(x, y, currentPlayer); if (pieces != null) { CheckWinner(); if (currentPlayer == PiecesType.BLACK) { currentPlayer = PiecesType.WHITE; } else if (currentPlayer == PiecesType.WHITE) { currentPlayer = PiecesType.BLACK; } return(pieces); } return(null); }