private void ClickEvent(object sender, EventArgs e) { if (IsMyTurn) { Button btn = sender as Button; if (btn.BackgroundImage != null) { return; } TurnInfo nextTurn = new TurnInfo() { CurrentPlayer = CurrentPlayer, Coordinate = GetChessPoint(btn) }; turnStack.Push(nextTurn); SocketData positonData = new SocketData(); positonData.Command = (int)SocketCommand.SEND_COORDINATE; positonData.Point = GetChessPoint(btn); gameSocket.Send(positonData); MarkASquare(btn); ChangePlayer(); if (playerMarkEvent != null) { playerMarkEvent(this, new EventArgs()); } if (IsEndGame(btn)) { EndGame(); if (GAME_MODE == CaroConstant.GAME_MODE_LAN) { SocketData gameOverData = new SocketData(); gameOverData.Command = (int)SocketCommand.END_GAME; SendData(gameOverData); } } } else { MessageBox.Show("Chưa tới lượt của bạn"); } }
public bool Undo() { // if stack empty, can't undo if (turnStack.Count < 1) { return(false); } // remove background image TurnInfo lastTurn = turnStack.Pop(); Point lastCoordinate = lastTurn.Coordinate; Matrix[lastCoordinate.X][lastCoordinate.Y].BackgroundImage = null; CurrentPlayer = lastTurn.CurrentPlayer; ChangePlayer(); return(true); }