private void Delete_a_Chess() { if (cb_client.chessBoard.chesses_oder.Count > 0 && cb_client.usercontrol_chessbutton.Count > 0) { //获取最后一颗棋子的模型 GoBang_Lib.Chess peekchess = cb_client.chessBoard.chesses_oder.Pop(); int x = peekchess.x, y = peekchess.y; //在棋盘模型中清除 cb_client.chessBoard.Board[x, y].type = GoBang_Lib.Type.Empety; //视图中移除 UserControl_ChessButton cb = cb_client.usercontrol_chessbutton.Pop(); cb_client.BoardGrid_usercontrol.Children.Remove(cb); //把上一个棋子标记为新 if (cb_client.usercontrol_chessbutton.Count != 0) { cb_client.chessBoard.chesses_oder.Peek().isnew = true; cb_client.usercontrol_chessbutton.Peek().Isnew = true; } //对局次数减一 times--; SwitchPlayer(); } }
private bool PutChess(int col, int row) { if (iswin) { return(false); } //判断此处是否有棋了------------------------------------------------------------------------------------------ if (cb_client.chessBoard.Board[col, row].type != GoBang_Lib.Type.Empety) { System.Windows.MessageBox.Show("(" + (col + 1) + "," + (row + 1) + ")已经有棋子了"); return(false); } //修改上一个棋子------------------------------------------------------------------------------------------ if (cb_client.usercontrol_chessbutton.Count != 0) { cb_client.chessBoard.chesses_oder.Peek().isnew = false; cb_client.usercontrol_chessbutton.Peek().Isnew = false; } soundplayer.Play(); //模型下棋------------------------------------------------------------------------------------------ GoBang_Lib.Chess chess = cb_client.chessBoard.Board[col, row]; chess.isnew = true; chess.number = times; chess.type = player; cb_client.chessBoard.chesses_oder.Push(chess); //局数+1------------------------------------------------------------------------------------------ times++; //图形下棋------------------------------------------------------------------------------------------ UserControl_ChessButton chessButton = new UserControl_ChessButton(new GoBang_Lib.Chess(player, times, true, col, row)); cb_client.BoardGrid_usercontrol.Children.Add(chessButton); cb_client.usercontrol_chessbutton.Push(chessButton); Grid.SetRow(chessButton, row); Grid.SetColumn(chessButton, col); //判断是否胜利------------------------------------------------------------------------------------------ if (GoBang_Lib.Tools.IsWin(cb_client.chessBoard, col, row)) { iswin = true; string win = player == GoBang_Lib.Type.Black ? "黑棋获胜" : "白棋获胜"; System.Windows.MessageBox.Show(win); System.Threading.Thread.Sleep(1000); } else { SwitchPlayer(); pb_client.ResetTime(); } return(true); }