private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { if (isOnl == false) { #region offline # region nguoi choi if (numplayer == 2) { var element = (UIElement)e.Source; int c = Grid.GetColumn(element); int r = Grid.GetRow(element); string temp = "Column : "; temp += c; temp += "Row:"; temp += r; if (chess_Board.Board[c, r] == 0 && winner == 0) { double width = chessGrid.Width / 12; double height = chessGrid.Height / 12; chess_Board.play(c, r, activer); if (chess_Board.checkWin(c, r) != 0) { MessageBox.Show("Winner is player" + activer); winner = activer; } if (activer == 1) { activer = 2; } else { activer = 1; } } else { if (winner == 0) { MessageBox.Show("o nay da duoc danh"); } else { MessageBox.Show("da co nguoi thang cuoc"); } } } #endregion # region may choi voi nguoi else { if (activer == 1)
public void connected(Quobject.SocketIoClientDotNet.Client.Socket socket, string name) { socket.On(Socket.EVENT_CONNECT, () => { MessageBox.Show("connected", "Thông báo "); }); socket.On(Socket.EVENT_MESSAGE, (data) => { MessageBox.Show(data.ToString()); }); socket.On(Socket.EVENT_CONNECT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("ChatMessage", (data) => { MessageBox.Show(data.ToString()); if (((Newtonsoft.Json.Linq.JObject)data)["message"].ToString() == "Welcome!") { socket.Emit("MyNameIs", name); socket.Emit("ConnectToOtherPlayer"); } string mes = ((Newtonsoft.Json.Linq.JObject)data)["message"].ToString(); if (mes.Contains("You are the first player!") == true) { activer = 2; } }); socket.On(Socket.EVENT_ERROR, (data) => { MessageBox.Show(data.ToString()); }); socket.On("NextStepIs", (data) => { MessageBox.Show(data.ToString()); var o = JObject.Parse(data.ToString()); activer = (int)o["player"]; row = (int)o["row"]; column = (int)o["col"]; MessageBox.Show(row + " " + column + " " + activer); if (activer == 1) { board.play(column, row, activer); activer = 2; } if (activer == 2) { activer = 2; } }); }
public void play(chessBoard board) { if (isActi == false) { return; } else { //int count = 0; Cell check = null; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 4, board); if (check == null) { check = checkDiagonalLine(i, j, 4, board); } if (check != null) { board.play(check.c, check.r, 2); if (board.checkWin(check.c, check.r) == 1) { isWin = true; } return; } } } } if (check == null) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 3, board); if (check == null) { check = checkDiagonalLine(i, j, 3, board); } if (check != null) { board.play(check.c, check.r, 2); return; } } } } } if (check == null) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 2, board); if (check == null) { check = checkDiagonalLine(i, j, 2, board); } if (check != null) { board.play(check.c, check.r, 2); return; } } } } } if (check == null) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 1, board); if (check == null) { check = checkDiagonalLine(i, j, 1, board); } if (check != null) { board.play(check.c, check.r, 2); return; } } } } } isActi = false; return; } }
public void play(chessBoard board) { if (isActi == false) return; else { //int count = 0; Cell check = null; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 4, board); if (check == null) check = checkDiagonalLine(i, j, 4, board); if (check != null) { board.play(check.c, check.r, 2); if (board.checkWin(check.c, check.r) == 1) isWin = true; return; } } } } if(check == null) { for (int i = 0; i < 12; i++) for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 3, board); if (check == null) check = checkDiagonalLine(i, j, 3, board); if (check != null) { board.play(check.c, check.r, 2); return; } } } } if (check == null) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 2, board); if (check == null) check = checkDiagonalLine(i, j, 2, board); if (check != null) { board.play(check.c, check.r, 2); return; } } } } } if (check == null) { for (int i = 0; i < 12; i++) for (int j = 0; j < 12; j++) { if (board.Board[i, j] != 0) { check = checkInLine(i, j, 1, board); if (check == null) check = checkDiagonalLine(i, j, 1, board); if (check != null) { board.play(check.c, check.r, 2); return; } } } } isActi = false; return; } }