Exemplo n.º 1
0
        private void RefreshChessBoard()
        {
            var pieceBeingMoved = _currentSelectedPiece.Piece;

            var fromControl = ChessBoard.GetControlFromPosition(pieceBeingMoved.FromCoOrdinate.XCoOrdinate, pieceBeingMoved.FromCoOrdinate.YCoOrdinate);
            var toControl   = ChessBoard.GetControlFromPosition(pieceBeingMoved.CurrentCoOrdinate.XCoOrdinate, pieceBeingMoved.CurrentCoOrdinate.YCoOrdinate);

            var toControlNew   = CreateButton(pieceBeingMoved.FromCoOrdinate.XCoOrdinate, pieceBeingMoved.FromCoOrdinate.YCoOrdinate);
            var fromControlNew = CreateButton(pieceBeingMoved.CurrentCoOrdinate.XCoOrdinate, pieceBeingMoved.CurrentCoOrdinate.YCoOrdinate);

            fromControlNew.Name = toControl.Name;

            var boardState = _game.GetState();

            Piece piece;

            if (boardState.LayOut.TryGetValue(pieceBeingMoved.CurrentCoOrdinate, out piece))
            {
                fromControlNew.Image = piece.Image;
            }
            fromControlNew.Piece = piece;

            ChessBoard.Controls.Remove(fromControl);
            ChessBoard.Controls.Remove(toControl);
            toControl.Dispose();
            fromControl.Dispose();
            ChessBoard.Controls.Add(fromControlNew, pieceBeingMoved.CurrentCoOrdinate.XCoOrdinate, pieceBeingMoved.CurrentCoOrdinate.YCoOrdinate);
            ChessBoard.Controls.Add(toControlNew, pieceBeingMoved.FromCoOrdinate.XCoOrdinate, pieceBeingMoved.FromCoOrdinate.YCoOrdinate);
        }
Exemplo n.º 2
0
 void RedrawBoard()
 {
     for (int i = 0; i < Game.Board.GetLength(0); i++)
     {
         for (int j = 0; j < Game.Board.GetLength(1); j++)
         {
             var pictureBox = ChessBoard.GetControlFromPosition(j, i) as PictureBox;
             if (Game.Board[i, j] != null)
             {
                 pictureBox.Image = Game.Board[i, j].FigureSprite;
             }
             else
             {
                 pictureBox.Image = null;
             }
         }
     }
     PlayerTurnLabel.Text = "Player Turn:" + Game.PlayerTurn.ToString();
 }