예제 #1
0
파일: Snake.cs 프로젝트: Sp00nyMan/Snake
        private bool CollidedAWall(uint fieldSize, ref BodyPart head)
        {
            if (head.x < 0)
            {
                head.move(new BodyPart((int)fieldSize - 1, head.y));
            }
            else if (head.x >= fieldSize)
            {
                head.move(new BodyPart(0, head.y));
            }
            else if (head.y < 0)
            {
                head.move(new BodyPart(head.x, (int)fieldSize - 1));
            }
            else if (head.y >= fieldSize)
            {
                head.move(new BodyPart(head.x, 0));
            }

/*			if (head.x < 0 || head.x >= fieldSize || head.y < 0 || head.y >= fieldSize)
 *                              return true;*/
            return(false);
        }
예제 #2
0
파일: Snake.cs 프로젝트: Sp00nyMan/Snake
        private void Move(ref BodyPart head, Diractions?dir)
        {
            int xOffset = 0, yOffset = 0;

            if (dir == null)
            {
                dir = direction;
            }
            switch (dir)
            {
            case Diractions.Up:
                if (direction == Diractions.Down)                         //Tried to move up while moving down
                {
                    goto case Diractions.Down;
                }
                yOffset   = -1;
                direction = Diractions.Up;
                break;

            case Diractions.Down:
                if (direction == Diractions.Up)                         //Tried to move down while moving up
                {
                    goto case Diractions.Up;
                }
                yOffset   = 1;
                direction = Diractions.Down;
                break;

            case Diractions.Left:
                if (direction == Diractions.Right)                         //Tried to move left while moving right
                {
                    goto case Diractions.Right;
                }
                xOffset   = -1;
                direction = Diractions.Left;
                break;

            case Diractions.Right:
                if (direction == Diractions.Left)                         //Tried to move right while moving left
                {
                    goto case Diractions.Left;
                }
                xOffset   = 1;
                direction = Diractions.Right;
                break;
            }

            head.move(xOffset, yOffset);
        }