예제 #1
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
            }
        }
예제 #2
0
        public override void InitializeNewComponent(IDictionary defaultValues)
        {
            base.InitializeNewComponent(defaultValues);
            IChessboardTile childAtPoint = (this.Component as Control).Parent as IChessboardTile; // ((Control)this.Component).FindForm().GetChildAtPoint(new Point(checked(((Control)this.Component).Location.X), checked(((Control)this.Component).Location.Y)));
            ////this.
            IChessboardTile tile = (this.Component as UiChessPiece).Parent as IChessboardTile;

            //MessageBox.Show(v?.Rank.ToString());
            //Type type = typeof(IChessboardTile);
            if (tile != null)
            {
                UiChessPiece                uiPiece          = this.Component as UiChessPiece;
                BoardCoordinate             cords            = new BoardCoordinate(tile.Rank, tile.File);
                Dictionary <object, object> pieceArgs        = new Dictionary <object, object>();
                ChessPieceColor             pieceOriantation = ((int)cords.Rank < 5) ? ChessPieceColor.White : ChessPieceColor.Black;
                //pieceArgs.Add
                //this.InitializeNewComponent(pieceArgs);
                //uiPiece.Piece = null;
                uiPiece.OwningPlayerOrientation = pieceOriantation;
                uiPiece.InitialBoardCoordinate  = new BoardCoordinate(tile.Rank, tile.File);
                //uiPiece.DesignerInitialized(cords, pieceOriantation);
                //((IDesignerHost)this.ParentComponent.Site.GetService(typeof(IDesignerHost))).Container.Add(this.Component);
                //if (childAtPoint.Controls.OfType<DataGridViewFooter>().Count<DataGridViewFooter>() > 0)
                //{
                //    this.KillComponent(((Control)this.Component).Name + " Not Allowed! \rOnly one footer per DataGridView!");
                //}
                //else
                //{
                //    if (((Control)this.Component).Parent.GetType() == typeof(DataGridView))
                //        return;
                //    ((Control)this.Component).Parent = childAtPoint;
                //    DataGridViewFooter component = (DataGridViewFooter)this.Component;
                //    DataGridView dgv = (DataGridView)childAtPoint;
                //    component.SetParent(ref dgv);
                //    ((IDesignerHost)this.ParentComponent.Site.GetService(typeof(IDesignerHost))).Container.Add(this.Component);
                //}
            }
            //else
            //    this.KillComponent("Chess Piece can only be added to a ChessTile");
        }
예제 #3
0
 public PieceAttackEventArgs(bool isValid, BoardCoordinate from, BoardCoordinate attackAt, UiChessPiece attacker, UiChessPiece attackee)
 {
     this.IsValid           = isValid;
     this.From              = from;
     this.AttackCoordinates = attackAt;
     this.Attacker          = attacker;
     this.Attackee          = attackee;
 }