Beispiel #1
0
    bool willCollide(Utils.InstructionType catAction, Utils.InstructionType dogAction)
    {
        if (!PuzzleManager.stageInfo.hasCat || !PuzzleManager.stageInfo.hasDog)
        {
            return(false);
        }

        int cat_x = puzzleManager.catPosition[0];
        int cat_y = puzzleManager.catPosition[1];
        int dog_x = puzzleManager.dogPosition[0];
        int dog_y = puzzleManager.dogPosition[1];

        int[] cat_dest = { 0, 0 }, dog_dest = { 0, 0 };
        switch (catAction)
        {
        case Utils.InstructionType.MOVE_U:
            cat_dest = getCatDestination('U');
            break;

        case Utils.InstructionType.MOVE_L:
            cat_dest = getCatDestination('L');
            break;

        case Utils.InstructionType.MOVE_R:
            cat_dest = getCatDestination('R');
            break;

        case Utils.InstructionType.MOVE_D:
            cat_dest = getCatDestination('D');
            break;

        case Utils.InstructionType.GRAB_U:
            cat_dest = getCatDestination('U');
            break;

        case Utils.InstructionType.GRAB_L:
            cat_dest = getCatDestination('L');
            break;

        case Utils.InstructionType.GRAB_R:
            cat_dest = getCatDestination('R');
            break;

        case Utils.InstructionType.GRAB_D:
            cat_dest = getCatDestination('D');
            break;

        default:
            cat_dest = new int[] { -1, -1 };
            break;
        }
        switch (dogAction)
        {
        case Utils.InstructionType.MOVE_U:
            dog_dest = getDogDestination('U');
            break;

        case Utils.InstructionType.MOVE_L:
            dog_dest = getDogDestination('L');
            break;

        case Utils.InstructionType.MOVE_R:
            dog_dest = getDogDestination('R');
            break;

        case Utils.InstructionType.MOVE_D:
            dog_dest = getDogDestination('D');
            break;

        case Utils.InstructionType.GRAB_U:
            dog_dest = getDogDestination('U');
            break;

        case Utils.InstructionType.GRAB_L:
            dog_dest = getDogDestination('L');
            break;

        case Utils.InstructionType.GRAB_R:
            dog_dest = getDogDestination('R');
            break;

        case Utils.InstructionType.GRAB_D:
            dog_dest = getDogDestination('D');
            break;

        default:
            dog_dest = new int[] { -2, -2 };
            break;
        }
        int cat_dest_x = cat_dest[0];
        int cat_dest_y = cat_dest[1];
        int dog_dest_x = dog_dest[0];
        int dog_dest_y = dog_dest[1];

        // Both moving
        if (Utils.IsMovementType(catAction) && Utils.IsMovementType(dogAction))
        {
            if (cat_dest_x == dog_dest_x && cat_dest_y == dog_dest_y)
            {
                // They collided
                Debug.Log("They collided");
                missionResult = MissionResult.Condition.CAT_DOG_WALK_INTO_EACH_OTHER_FAIL;
                StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
                StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
                return(true);
            }
            if (cat_dest_x == dog_x && cat_dest_y == dog_y && cat_x == dog_dest_x && cat_y == dog_dest_y)
            {
                // They went through each other
                Debug.Log("They went through each other");
                missionResult = MissionResult.Condition.CAT_DOG_WALK_INTO_EACH_OTHER_FAIL;
                StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
                StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
                return(true);
            }
        }
        // Cat moving
        if (Utils.IsMovementType(catAction))
        {
            if (cat_dest_x == dog_dest_x && cat_dest_y == dog_dest_y)
            {
                // Cat ran into grab
                Debug.Log("Cat ran into grab");
                if (dogIsHoldingKind == PuzzleManager.PuzzleObject.NTH)
                {
                    missionResult = MissionResult.Condition.DOG_GRAB_FAIL;
                }
                else
                {
                    missionResult = MissionResult.Condition.DOG_PLACE_FAIL;
                }
                StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
                StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
                return(true);
            }
            if (cat_dest_x == dog_x && cat_dest_y == dog_y)
            {
                // Cat ran into dog
                Debug.Log("Cat ran into dog");
                missionResult = MissionResult.Condition.CAT_WALK_FAIL;
                StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
                StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
                return(true);
            }
        }
        // Dog moving
        if (Utils.IsMovementType(dogAction))
        {
            if (cat_dest_x == dog_dest_x && cat_dest_y == dog_dest_y)
            {
                // Dog ran into grab
                Debug.Log("Dog ran into grab");
                if (catIsHoldingKind == PuzzleManager.PuzzleObject.NTH)
                {
                    missionResult = MissionResult.Condition.CAT_GRAB_FAIL;
                }
                else
                {
                    missionResult = MissionResult.Condition.CAT_PLACE_FAIL;
                }
                StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
                StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
                return(true);
            }
            if (dog_dest_x == cat_x && dog_dest_y == cat_y)
            {
                // Cat ran into dog
                Debug.Log("Dog ran into cat");
                missionResult = MissionResult.Condition.DOG_WALK_FAIL;
                StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
                StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
                return(true);
            }
        }
        // Grab
        if (cat_dest_x == dog_x && cat_dest_y == dog_y)
        {
            // Cat grabbed dog
            Debug.Log("Cat grabbed dog");
            if (catIsHoldingKind == PuzzleManager.PuzzleObject.NTH)
            {
                missionResult = MissionResult.Condition.CAT_GRAB_FAIL;
            }
            else
            {
                missionResult = MissionResult.Condition.CAT_PLACE_FAIL;
            }
            StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
            StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
            return(true);
        }
        if (cat_x == dog_dest_x && cat_y == dog_dest_y)
        {
            // Dog grabbed cat
            Debug.Log("Dog grabbed cat");
            if (dogIsHoldingKind == PuzzleManager.PuzzleObject.NTH)
            {
                missionResult = MissionResult.Condition.DOG_GRAB_FAIL;
            }
            else
            {
                missionResult = MissionResult.Condition.DOG_PLACE_FAIL;
            }
            StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
            StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
            return(true);
        }
        if (cat_dest_x == dog_dest_x && cat_dest_y == dog_dest_y)
        {
            // Grabs clashed
            Debug.Log("Grabs clashed");
            if (catIsHoldingKind == PuzzleManager.PuzzleObject.NTH)
            {
                missionResult = MissionResult.Condition.CAT_GRAB_FAIL;
            }
            else
            {
                missionResult = MissionResult.Condition.CAT_PLACE_FAIL;
            }
            StartCoroutine(moveCatFailTransition(catAction.ToString()[catAction.ToString().Length - 1]));
            StartCoroutine(moveDogFailTransition(dogAction.ToString()[dogAction.ToString().Length - 1]));
            return(true);
        }

        return(false);
    }