Пример #1
0
 protected virtual void HandleKeyDown(ConsoleKeyDownEventArgs args)
 {
     if (args.KeyInfo.Key == ConsoleKey.Spacebar)
     {
         this.BulletShoot();
     }
     else if (args.KeyInfo.Key == ConsoleKey.B)
     {
         this.ThrowBomb();
     }
     else if (args.KeyInfo.Key == ConsoleKey.LeftArrow)
     {
         this.moveDirection = MoveDirectionType.Left;
     }
     else if (args.KeyInfo.Key == ConsoleKey.RightArrow)
     {
         this.moveDirection = MoveDirectionType.Right;
     }
     else if (args.KeyInfo.Key == ConsoleKey.DownArrow)
     {
         this.moveDirection = MoveDirectionType.Down;
     }
     else if (args.KeyInfo.Key == ConsoleKey.UpArrow)
     {
         this.moveDirection = MoveDirectionType.Up;
     }
 }
Пример #2
0
        public Rectangle GetAnimation(int x, MoveDirectionType moveDirection)
        {
            switch (moveDirection)
            {
            case MoveDirectionType.None:
                column = 0;
                break;

            case MoveDirectionType.Left:
                column = GetAnimationColumn(x, animateLeftColumns);
                break;

            case MoveDirectionType.Right:
                column = GetAnimationColumn(x, animateRightColumns);
                break;

            case MoveDirectionType.Up:
                column = 3;
                break;

            case MoveDirectionType.Down:
                column = 4;
                break;
            }

            return(new Rectangle((textureInfo.Width + spacer) * column, 0, textureInfo.Width, textureInfo.Height));
        }
Пример #3
0
 public void TurnAround()
 {
     if (moveDirection == MoveDirectionType.Left)
     {
         moveDirection = MoveDirectionType.Right;
     }
     else if (moveDirection == MoveDirectionType.Right)
     {
         moveDirection = MoveDirectionType.Left;
     }
 }
Пример #4
0
        protected Fighter(Field field, Point2D position, IList <IList <Pixel> > bodyStates, EntityStateType entityState) :
            base(field, position, bodyStates, entityState)
        {
            this.Name     = Constants.NameNotSet;
            this.bullets  = new List <Bullet>();
            this.bombs    = new List <Bomb>();
            this.missiles = new List <Missile>();

            this.moveDirection = MoveDirectionType.OnHold;

            ConsoleKeyboardHandler.Instance.KeyDown += this.Instance_KeyDown;
        }
Пример #5
0
        public int MoveHorizontally(bool isRight, bool isLeft, float deltaTime)
        {
            if (isRight)
            {
                moveDirection = MoveDirectionType.Right;
                return((int)(speed * deltaTime));
            }

            if (isLeft)
            {
                moveDirection = MoveDirectionType.Left;
                return(-(int)(speed * deltaTime));
            }

            return(0);
        }
Пример #6
0
        private void MoveItem(string item, MoveDirectionType direction)
        {
            if (temporaryListItems.ContainsKey(item))
            {
                string oldValue = temporaryListItems[item];

                int currentIndex = 0;
                foreach (KeyValuePair <string, string> keyPair in temporaryListItems)
                {
                    //exit if the key is the same
                    if (keyPair.Key == item)
                    {
                        break;
                    }
                    currentIndex++;
                }

                Dictionary <string, string> newList = new Dictionary <string, string>();
                int i = 0;
                foreach (KeyValuePair <string, string> keyPair in temporaryListItems)
                {
                    if (i == currentIndex - 1 && direction == MoveDirectionType.Up)
                    {
                        newList.Add(item, oldValue);
                    }
                    if (i != currentIndex)
                    {
                        newList.Add(keyPair.Key, keyPair.Value);
                    }
                    if (i == currentIndex + 1 && direction == MoveDirectionType.Down)
                    {
                        newList.Add(item, oldValue);
                    }

                    i++;
                }
                temporaryListItems = newList;
            }

            BindItems();
        }
Пример #7
0
        public virtual void Move()
        {
            if (this.moveDirection == MoveDirectionType.Left && this.Body.Exists(pixel => pixel.Coordinate.X > this.Width))
            {
                this.Position.X--;
            }
            else if (this.moveDirection == MoveDirectionType.Right && this.Body.Exists(pixel => pixel.Coordinate.X + this.Width < this.Field.PlayWidth - (this.Field.PlayWidth / 3)))
            {
                this.Position.X++;
            }
            else if (this.moveDirection == MoveDirectionType.Down && this.Body.Exists(pixel => pixel.Coordinate.Y + this.Height < this.Field.PlayHeight - 1))
            {
                this.Position.Y++;
            }
            else if (this.moveDirection == MoveDirectionType.Up && this.Body.Exists(pixel => pixel.Coordinate.Y > this.Height))
            {
                this.Position.Y--;
            }

            this.moveDirection = MoveDirectionType.OnHold;
        }
Пример #8
0
        public int MoveVertically(bool isUp, bool isDown, float deltaTime)
        {
            int move = 0;

            lastJumpTime += deltaTime;

            if (isDown)
            {
                moveDirection = MoveDirectionType.Down;
            }
            else
            {
                moveDirection = MoveDirectionType.None;
            }

            if (isUp)
            {
                HandleJump(deltaTime);
            }

            if (isJumping)
            {
                move          = -(int)(jumpSpeed * deltaTime);
                jumpTime     += deltaTime;
                moveDirection = MoveDirectionType.Up;

                if (jumpTime > maxJumpTime)
                {
                    isJumping = false;
                    jumpTime  = 0;
                }
            }
            else
            {
                move = (int)(fallSpeed * deltaTime);
            }

            return(move);
        }
Пример #9
0
 public Rectangle GetAnimation(int x, MoveDirectionType moveDirection)
 {
     return(new Rectangle(0, 0, textureInfo.Width, textureInfo.Height));
 }
Пример #10
0
 public CritterMoveHandler(int speed, MoveDirectionType initialMoveDirection)
 {
     this.speed    = speed;
     moveDirection = initialMoveDirection;
 }
Пример #11
0
 public Critter(int x, int y, TextureInfo textureInfo, float scale, int speed, MoveDirectionType initialMoveDirection, int score) : base(x, y, textureInfo, scale, score)
 {
     moveHandler = new CritterMoveHandler(speed, initialMoveDirection);
 }
Пример #12
0
    // stright line move
    public static bool GetStraightMoveList( ChessBoard board, ChessBoardSquare selSquare, List<sMove> listRetBoardPos, MoveDirectionType moveDirection )
    {
        ChessPosition srcPos = selSquare.position;
        PlayerSide srcPlayerSide = selSquare.piece.playerSide;

        ChessPosition movePos = new ChessPosition(srcPos.pos);

        // all(radial) direction one move
        int nTempRank, nTempPile;

        int nIterCount;
        nIterCount = GetNumDirectionIterCount( movePos.nRank, movePos.nPile, moveDirection );
        //UnityEngine.Debug.LogError( "GetStraightMoveList() - nIterCount = " + nIterCount + " movePos.nRank, movePos.nPile " + movePos.nRank + " " + movePos.nPile );

        for( int nCurrIter=1; nCurrIter<=nIterCount; nCurrIter++ ) {

            nTempRank = 0;
            nTempPile = 0;

            GetNextDirectionRankPile( ref nTempRank, ref nTempPile, moveDirection, nCurrIter );
            //UnityEngine.Debug.LogError( "GetStraightMoveList() - nTempRank, nTempPile " + nTempRank + " " + nTempPile );

            movePos.SetPosition( srcPos );
            bool bValidMove = movePos.MovePosition( nTempRank, nTempPile );
            if( bValidMove ) {

                UnityEngine.Debug.LogError( "GetStraightMoveList() - bValidMove - nTempRank, nTempPile " + nTempRank + " " + nTempPile );

                ChessBoardSquare trgSquare = board.aBoardSquare[movePos.nPile, movePos.nRank];
                // normal move
                if( trgSquare.IsBlank() ) {

                    sMove move = new sMove();

                    // normal move
                    move.moveType = MoveType.eNormal_Move;

                    move.srcSquare = selSquare;
                    move.trgSquare = trgSquare;

                    listRetBoardPos.Add( move );
                }
                // capture move
                else if( trgSquare.IsEnemy( srcPlayerSide ) ) {

                    sMove move = new sMove();

                    // normal move
                    move.moveType = MoveType.eCapture_Move;

                    move.srcSquare = selSquare;
                    move.trgSquare = trgSquare;

                    listRetBoardPos.Add( move );

                    return true;
                }
                // our piece
                else {

                    if( nCurrIter > 1 )
                        return true;
                    return false;
                }
            }
        }

        return false;
    }
Пример #13
0
    // sub move method
    // helper method
    public static int GetNumDirectionIterCount( int nCurrRank, int nCurrPile, MoveDirectionType moveDirection )
    {
        int nNumRamnatSqure = 0, nNumRamnatRank, nNumRamnatPile;
        switch( moveDirection ) {

            case MoveDirectionType.eDirection_Move_Left:
            {
                nNumRamnatSqure = nCurrRank;
            }
            break;

            case MoveDirectionType.eDirection_Move_Right:
            {
                nNumRamnatSqure = ChessData.nNumRank - (nCurrRank + 1);
            }
            break;

            case MoveDirectionType.eDirection_Move_Up:
            {
                nNumRamnatSqure = ChessData.nNumPile - (nCurrPile + 1);
            }
            break;

            case MoveDirectionType.eDirection_Move_Down:
            {
                nNumRamnatSqure = nCurrPile;
            }
            break;

            case MoveDirectionType.eDirection_Move_LeftUp_Diagonal:
            {
                nNumRamnatRank = nCurrRank;
                nNumRamnatPile = ChessData.nNumPile - (nCurrPile + 1);
                nNumRamnatSqure = Math.Min( nNumRamnatRank, nNumRamnatPile );
            }
            break;

            case MoveDirectionType.eDirection_Move_LeftDown_Diagonal:
            {
                nNumRamnatRank = nCurrRank;
                nNumRamnatPile = nCurrPile;
                nNumRamnatSqure = Math.Min( nNumRamnatRank, nNumRamnatPile );
            }
            break;

            case MoveDirectionType.eDirection_Move_RightUp_Diagonal:
            {
                nNumRamnatRank = ChessData.nNumRank - (nCurrRank + 1);
                nNumRamnatPile = ChessData.nNumPile - (nCurrPile + 1);
                nNumRamnatSqure = Math.Min( nNumRamnatRank, nNumRamnatPile );
            }
            break;

            case MoveDirectionType.eDirection_Move_RightDown_Diagonal:
            {
                nNumRamnatRank = ChessData.nNumRank - (nCurrRank + 1);
                nNumRamnatPile = nCurrPile;
                nNumRamnatSqure = Math.Min( nNumRamnatRank, nNumRamnatPile );
            }
            break;
        }

        return nNumRamnatSqure;
    }
Пример #14
0
    public static void GetNextDirectionRankPile( ref int nNextRank, ref int nNextPile, MoveDirectionType moveDirection, int nCurrIter )
    {
        switch( moveDirection ) {

            case MoveDirectionType.eDirection_Move_Left:
            {
                nNextRank = -nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_Right:
            {
                nNextRank = nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_Up:
            {
                nNextPile = nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_Down:
            {
                nNextPile = -nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_LeftUp_Diagonal:
            {
                nNextRank = -nCurrIter;
                nNextPile = nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_LeftDown_Diagonal:
            {
                nNextRank = -nCurrIter;
                nNextPile = -nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_RightUp_Diagonal:
            {
                nNextRank = nCurrIter;
                nNextPile = nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_RightDown_Diagonal:
            {
                nNextRank = nCurrIter;
                nNextPile = -nCurrIter;
            }
            break;

            case MoveDirectionType.eDirection_Move_Steep_LeftUp_Leap:
            {
                nNextRank = -1;
                nNextPile = 2;
            }
            break;

            case MoveDirectionType.eDirection_Move_Steep_LeftDown_Leap:
            {
                nNextRank = -1;
                nNextPile = -2;
            }
            break;

            case MoveDirectionType.eDirection_Move_Steep_RightUp_Leap:
            {
                nNextRank = 1;
                nNextPile = 2;
            }
            break;

            case MoveDirectionType.eDirection_Move_Steep_RightDown_Leap:
            {
                nNextRank = 1;
                nNextPile = -2;
            }
            break;

            case MoveDirectionType.eDirection_Move_NonSteep_LeftUp_Leap:
            {
                nNextRank = -2;
                nNextPile = 1;
            }
            break;

            case MoveDirectionType.eDirection_Move_NonSteep_LeftDown_Leap:
            {
                nNextRank = -2;
                nNextPile = -1;
            }
            break;

            case MoveDirectionType.eDirection_Move_NonSteep_RightUp_Leap:
            {
                nNextRank = 2;
                nNextPile = 1;
            }
            break;

            case MoveDirectionType.eDirection_Move_NonSteep_RightDown_Leap:
            {
                nNextRank = 2;
                nNextPile = -1;
            }
            break;
        }
    }
Пример #15
0
    // leap move
    public static bool GetLeapMoveList( ChessBoard board, ChessBoardSquare selSquare, List<sMove> listRetBoardPos, MoveDirectionType moveDirection )
    {
        ChessPosition srcPos = selSquare.position;
        PlayerSide srcPlayerSide = selSquare.piece.playerSide;

        ChessPosition movePos = new ChessPosition(srcPos.pos);

        // all(radial) direction one move
        int nTempRank = 0, nTempPile = 0;

        GetNextDirectionRankPile( ref nTempRank, ref nTempPile, moveDirection, 0 );

        movePos.SetPosition( srcPos );
        bool bValidMove = movePos.MovePosition( nTempRank, nTempPile );
        if( bValidMove ) {

            ChessBoardSquare trgSquare = board.aBoardSquare[movePos.nPile, movePos.nRank];
            // normal move
            if( trgSquare.IsBlank() ) {

                sMove move = new sMove();

                // normal move
                move.moveType = MoveType.eNormal_Move;

                move.srcSquare = selSquare;
                move.trgSquare = trgSquare;

                listRetBoardPos.Add( move );

                return true;
            }
            // capture move
            else if( trgSquare.IsEnemy( srcPlayerSide ) ) {

                sMove move = new sMove();

                // normal move
                move.moveType = MoveType.eCapture_Move;

                move.srcSquare = selSquare;
                move.trgSquare = trgSquare;

                listRetBoardPos.Add( move );

                return true;
            }
            // our piece
            else {

                return false;
            }
        }

        return false;
    }