Пример #1
0
    protected override void OnBeat()
    {
        switch (state)
        {
        default:
            break;

        case State.BUILD:

            BuildBox();


            boxCount--;



            switch (direction)
            {
            default:
            case Direction.UP:

                if (boxMan.GetArrayValue(xIndex + 1, yIndex) == 0)
                {
                    ChangeDirection();
                }
                else
                {
                    state = State.MOVE;
                }

                break;

            case Direction.DOWN:
                if (boxMan.GetArrayValue(xIndex - 1, yIndex) == 0)
                {
                    ChangeDirection();
                }
                else
                {
                    state = State.MOVE;
                }

                break;

            case Direction.RIGHT:
                if (boxMan.GetArrayValue(xIndex, yIndex + 1) == 0)
                {
                    ChangeDirection();
                }
                else
                {
                    state = State.MOVE;
                }

                break;

            case Direction.LEFT:
                if (boxMan.GetArrayValue(xIndex, yIndex - 1) == 0)
                {
                    ChangeDirection();
                }
                else
                {
                    state = State.MOVE;
                }

                break;
            }

            if (boxCount <= 0)     //if(xIndex <= 1 || xIndex >= 28 || yIndex <= 1 || yIndex >= 28)
            {
                ChangeDirection();
            }
            break;

        case State.MOVE:

            switch (direction)
            {
            default:
            case Direction.UP:
                MoveToBox(xIndex + 1, yIndex);
                break;

            case Direction.DOWN:
                MoveToBox(xIndex - 1, yIndex);
                break;

            case Direction.RIGHT:
                MoveToBox(xIndex, yIndex + 1);
                break;

            case Direction.LEFT:
                MoveToBox(xIndex, yIndex - 1);
                break;
            }

            //TargetPos += dir;
            //if (boxMan.GetArrayValue(xIndex, yIndex) == 1)
            state = State.BUILD;

            break;
        }
    }