Пример #1
0
        public void OnRaisePieceAttacking(PieceAttackEventArgs e)
        {
            PieceAttackingEventHandler handler = RaisePieceAttacking;

            if (handler != null)
            {
                handler(this, e);
                if (e.IsValid)
                {
                    PieceAttackEventArgs e2 = new PieceAttackEventArgs(e.IsValid,
                                                                       new BoardCoordinate(RankCoordinate.None, FileCoordinate.None),
                                                                       e.AttackCoordinates, e.Attacker, e.Attackee);
                    e.Attackee.RaisePieceAttacked(this, e2);
                }
            }
        }
Пример #2
0
        private void ImDropped()
        {
            PieceAttackEventArgs attackingEventArgs = null;
            Point dropPoint = this.GetMyLocationRelativeToForm();
            //Control myNewParent = this.GetFirstControlOfTypeAtPoint(this._chessboard, dropPoint, typeof(IChessboardTile));
            Control         myNewParent = this.FindForm().GetChildAtPoint(dropPoint);
            IChessboardTile myNewTile   = myNewParent as IChessboardTile;

            if (myNewParent == null || myNewTile == null)
            {
                return;
            }
            BoardCoordinate newTileCoordinate = new BoardCoordinate(myNewTile.Rank, myNewTile.File);
            bool            legalMove         = this.MoveTo(newTileCoordinate);
            UiChessPiece    occupyingPiece    = null;

            if (legalMove)
            {
                // find other chess piece in tile and if present
                occupyingPiece = this.GetFirstControlOfTypeAtPoint(this.FindForm(), dropPoint, typeof(UiChessPiece)) as UiChessPiece;

                // raise attack event
                if (occupyingPiece != null)
                {
                    attackingEventArgs = new PieceAttackEventArgs(true, this.CurrentLocation, newTileCoordinate, this, occupyingPiece);
                    this.RaisePieceAttacking(this, attackingEventArgs);
                }

                myNewParent.Controls.Add(this);
                this.BringToFront();
                this.Dock = DockStyle.Fill;


                if (occupyingPiece != null)
                {
                    this.RaisePieceAttacked(this, attackingEventArgs);
                }
            }
            else
            {
                // animate back to original tile
            }
        }