private void btn_reset_Click(object sender, EventArgs e) { myGame.ResetBoard(); PboxChess.Invalidate(); PBoxBlack.Invalidate(); PBoxWhite.Invalidate(); btn_reset.Enabled = false; }
private void button1_Click(object sender, EventArgs e) { game.Undo(); // отменяем ход черных game.Undo(); // отменяем ход белых game.Winner = CoreGame.Enums.GameSide.Undefined; PboxChess.Invalidate(); }
private void Form1_Load(object sender, EventArgs e) { //handle chess picturebox events PboxChess.Paint += PboxChess_Paint; PboxChess.MouseClick += OnClick; PBoxBlack.Paint += PboxBlack_Paint; PBoxWhite.Paint += PboxWhite_Paint; //handle chess library events myGame.GetPieceTransform += PromptForPeice; myGame.OnPieceMove += OnMove; myGame.OnEndGame += OnEndGame; myGame.OnPieceTaken += OnTake; PboxChess.Invalidate(); //invalidate for initial draw } //Hook events
//Form control event handlers private void OnClick(object sender, MouseEventArgs e) { //get 0-7 grid location of click Point loc = new Point((int)Math.Floor((e.X / (float)PboxChess.Width) * 8), 7 - (int)Math.Floor((e.Y / (float)PboxChess.Width) * 8)); if (!myGame.MakeMove(loc)) { myGame.SelectPeice(loc); } //if (myGame.SelectedPiece == null) { myGame.SelectPeice(loc); } //attempt to select piece at loc //else { myGame.MakeMove(loc); } //attempt to make move to selected loc PboxChess.Invalidate(); //redraw board }
// клик по игровому полю private void PboxChess_MouseClick(object sender, MouseEventArgs e) { var loc = new Point((int)Math.Floor((e.X / (float)PboxChess.Width) * 8), 7 - (int)Math.Floor((e.Y / (float)PboxChess.Width) * 8)); var peice = game.GetPeiceOnLocation(loc); // клетка на игровом поле if (peice.HaveFigure) // если клетка имеет фигуру { if (peice.Side == game.InnerGame.Turn) // если наш ход { game.SelectPeice(loc); // выбираем фигуру } else { game.MakeMove(loc, checkBox1.Checked); // иначе делаем ход выбранной фигурой (атака) } } else { game.MakeMove(loc, checkBox1.Checked); // иначе делаем ход выбранной фигурой (передвижение) } if (game.Winner != CoreGame.Enums.GameSide.Undefined) // если определен победитель - высвечиывааем его { if (game.Winner == CoreGame.Enums.GameSide.Black) { MessageBox.Show("Победили черные!"); } if (game.Winner == CoreGame.Enums.GameSide.White) { MessageBox.Show("Победили белые!"); } // начинаем заново, сбрасывая все состояния game.Winner = CoreGame.Enums.GameSide.Undefined; game.InnerGame.Reset(); var turn = game.InnerGame.Turn == GameSide.White ? GameSide.Black : GameSide.White; game.InnerGame = new ChessGame(turn, game.InnerGame.Board, game.InnerGame.GameMoves); return; } PboxChess.Invalidate(); }
private void button2_Click(object sender, EventArgs e) { game.InnerGame.Reset(); game.SelectedPeice = null; PboxChess.Invalidate(); }