Esempio n. 1
0
 private void SetCurrentAction(Act act)
 {
     if (act != null)
     {
         pb_curAct.Image = new Bitmap(act.Icon, pb_curAct.Size);
         ActionId        = act.Id;
         CAction         = act;
         ActionChanged?.Invoke(this, null);
     }
     else
     {
         pb_curAct.Image = new Bitmap(1, 1);
         ActionId        = -1;
         CAction         = null;
         ActionChanged?.Invoke(this, null);
     }
 }
Esempio n. 2
0
        private void RefreshDesires()
        {
            Desire oldAction = this.CurrentDesire;

            // If there are no items in the desires collection, we just go idle
            if (Desires.Count == 0)
            {
                this.CurrentDesire = new Desire()
                {
                    Reason   = "Walking around aimlessly...",
                    GainedAt = DateTime.Now,
                };
            }
            else
            {
                // Set our new interest to the first item in the queue
                this.CurrentDesire = Desires.Peek();
            }

            if (ActionChanged != null)
            {
                ActionChanged.Invoke(this, new ActionChangedEventArgs(oldAction.Reason, this.CurrentDesire.Reason));
            }
        }
Esempio n. 3
0
 private void OnActionDid(ActionEventArgs e) => ActionChanged?.Invoke(this, e);
Esempio n. 4
0
 protected internal void OnActionChanged(CacheValue cacheValue) => ActionChanged?.Invoke(cacheValue);
Esempio n. 5
0
 private void b_action_Click(object sender, EventArgs e)
 {
     ActionChanged?.Invoke(this, null);
     InvokeOnClick(this, e);
 }
Esempio n. 6
0
 private void NotifyActionChanged(IAction action)
 {
     ActionChanged?.Invoke(this, new ActionChangedEventArgs(action));
 }
Esempio n. 7
0
        private void Square_SecondClick(object sender, EventArgs e)
        {
            to = (Square)sender;

            if (light.MoveList.Count == 0)
            {
                ActionChanged?.Invoke(to, new ActionEventArgs(UserAction.None));
                return;
            }

            move = light.MoveList.FirstOrDefault(t => t.Square == to);

            if (move == null)
            {
                ActionChanged?.Invoke(to, new ActionEventArgs(UserAction.Invalid_Move));
                return;
            }

            if (move.Kind == UserAction.Move)
            {
                to.Piece         = from.Piece;
                to.Piece.Current = to;

                if (to.Piece.Name == Pieces.King)
                {
                    if (blackCanCastle || whiteCanCastle)
                    {
                        handleCastling();
                    }
                    shutOffCastling();
                }

                if (to.Piece.Name == Pieces.Rook)
                {
                    shutOffCastling();
                }

                if (to.Piece.Name == Pieces.Pawn)
                {
                    if ((from.Rank == 1 && to.Rank == 3) || (from.Rank == 6 && to.Rank == 4))
                    {
                        to.Piece.Passant = true;
                    }

                    // Capture passant
                    if (Math.Abs(from.File - to.File) == 1)
                    {
                        LastMove.Piece = null;
                        move.Kind      = UserAction.Capture;
                    }
                }
            }
            else if (move.Kind == UserAction.Capture)
            {
                ChessBoard.RemovePiece(to.Piece);
                to.Piece         = from.Piece;
                to.Piece.Current = to;
            }

            if (move.Kind == UserAction.Move || move.Kind == UserAction.Capture)
            {
                if (to.Piece.Name == Pieces.Pawn)
                {
                    if ((from.Rank == 1 && to.Rank == 3) || (from.Rank == 6 && to.Rank == 4))
                    {
                        to.Piece.Passant = true;
                    }

                    if (to.Rank == 0 || to.Rank == 7)
                    {
                        PromotedSquare = to;
                        ShowPieceSelector(from);
                    }
                }
            }

            var validMove = true;

            if (!catchOnDeepCheck)
            {
                validMove = detectCheck();
            }

            if (validMove)
            {
                // Move piece
                LastMove   = to;
                from.Piece = null;

                validMove        = deepCheckDetect();
                catchOnDeepCheck = !validMove;
            }

            if (validMove)
            {
                lastCheckPiece = null;
                ChangeTurn();
            }
            else
            {
                // Cancel Move
                from.Piece = to.Piece;
                ChessPiece a;

                if (WhosPlaying == PieceColor.White)
                {
                    a = ChessBoard.WhitePieces.FirstOrDefault(t => t.Id == from.Piece.Id);
                    from.Piece.Current = to;
                    a.Current          = from;
                }

                if (WhosPlaying == PieceColor.Black)
                {
                    a         = ChessBoard.BlackPieces.FirstOrDefault(t => t.Id == from.Piece.Id);
                    a.Current = from;
                }

                to.Piece  = null;
                move.Kind = UserAction.Invalid_Move;
            }

            ActionChanged?.Invoke(to, new ActionEventArgs(move.Kind));
        }
Esempio n. 8
0
 private void Square_FirstClick(object sender, EventArgs e)
 {
     from = (Square)sender;
     ActionChanged?.Invoke(from, new ActionEventArgs(UserAction.Piece_Selected));
 }