public ChessMan(string Name, TurnPlay SoHuu, Statue TrangThai, Color clrText) { this.Name = Name; this.SoHuu = SoHuu; this.TrangThai = TrangThai; this.clrText = clrText; }
public void Progress() { TurnPlay?.Invoke(this, new GameEventArgs(Game, null)); int inTurnPlayerIndex = Game.GameState.InTurnPlayerIndex; Turn turn = GameClients[inTurnPlayerIndex].GetTurn(Game); TurnResult turnResult = Game.PlayTurn(turn); TurnPlayed?.Invoke(this, new TurnEventArgs(Game, turn, turnResult)); }
private void DeleteEventFromChessMan(TurnPlay Curr) { if (Curr == TurnPlay.Player1) { for (int i = 0; i < lstCBPlayer1.Count; i++) { lstCBPlayer1[i].btn.Click -= ChessMan_Click; } } else { for (int i = 0; i < lstCBPlayer2.Count; i++) { lstCBPlayer2[i].btn.Click -= ChessMan_Click; } } }
private void CreateChessBoard() { lstChessBoard = new Button[Cons.ChessBoardSize, Cons.ChessBoardSize]; CurrentPlayer = TurnPlay.Player1; for (int i = 0; i < Cons.ChessBoardSize; i++) { for (int j = 0; j < Cons.ChessBoardSize; j++) { lstChessBoard[i, j] = new Button() { Location = new Point(j * Cons.ChessBoardWidth, Cons.ChessBoardHeight * i), Size = new System.Drawing.Size(Cons.ChessBoardWidth, Cons.ChessBoardHeight), Tag = i.ToString(), BackColor = Color.White }; pnlChessBoard.Controls.Add(lstChessBoard[i, j]); } } }
private ChessMan GetChessManByButton(Button btn, TurnPlay Curr) { if (Curr == TurnPlay.Player1) { foreach (ChessMan cm in lstCBPlayer1) { if (cm.btn == btn) { return(cm); } } } else { foreach (ChessMan cm in lstCBPlayer2) { if (cm.btn == btn) { return(cm); } } } return(null); }
void Move_Click(object sender, EventArgs e) { Button Move = sender as Button; HandleTheWayOfChessMan(OldChessMan, Color.White); if (Move.Text != "") { ChessMan Remove = GetChessManByButton((Button)sender, CurrentPlayer == TurnPlay.Player1 ? TurnPlay.Player2 : TurnPlay.Player1); DeleteChessMan(Remove); if (IsWin()) { MessageBox.Show(CurrentPlayer == TurnPlay.Player1 ? "Người chơi 1 thắng!" : "Người chơi 2 thắng"); pnlChessBoard.Enabled = false; btnEndGame.Visible = true; } } Move.Text = OldChessMan.Name; if (OldChessMan.btn.Text == "Chốt") { if (IsBecomeQueen(Int32.Parse(Move.Tag.ToString()))) { OldChessMan.Name = "Hậu"; Move.Text = "Hậu"; } } Move.ForeColor = OldChessMan.clrText; OldChessMan.btn.Text = ""; OldChessMan.btn.Click -= ChessMan_Click; OldChessMan.TrangThai = Statue.NotHit; OldChessMan.btn = Move; OldChessMan.btn.Click += ChessMan_Click; DeleteEventFromChessMan(CurrentPlayer); CurrentPlayer = CurrentPlayer == TurnPlay.Player1 ? TurnPlay.Player2 : TurnPlay.Player1; CreateEventForChessMan(CurrentPlayer); }