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); }
IEnumerator interpretationEvent() { catIndex = 0; dogIndex = 0; if (PuzzleManager.stageInfo.hasCat) { catArrow.gameObject.SetActive(true); } if (PuzzleManager.stageInfo.hasDog) { dogArrow.gameObject.SetActive(true); } yield return(new WaitForSeconds(catArrow.duration + secondsBetweenMoves)); while (catIndex < catInstructionList.list.Count || dogIndex < dogInstructionList.list.Count) { Utils.InstructionType catAction = Utils.InstructionType.WAIT, dogAction = Utils.InstructionType.WAIT; if (PuzzleManager.stageInfo.hasCat && catIndex < catInstructionList.list.Count) { catArrow.target = catIndex; } if (PuzzleManager.stageInfo.hasDog && dogIndex < dogInstructionList.list.Count) { dogArrow.target = dogIndex; } if (catIndex < catInstructionList.list.Count) { catAction = catInstructionList.list[catIndex].GetComponent <InstructionListNode>().instructionType; } if (dogIndex < dogInstructionList.list.Count) { dogAction = dogInstructionList.list[dogIndex].GetComponent <InstructionListNode>().instructionType; } if (willCollide(catAction, dogAction)) { missionFailed = true; } if (missionFailed) { break; } if (catIndex < catInstructionList.list.Count) { switch (catAction) { case Utils.InstructionType.MOVE_U: moveCat('U'); break; case Utils.InstructionType.MOVE_L: moveCat('L'); break; case Utils.InstructionType.MOVE_R: moveCat('R'); break; case Utils.InstructionType.MOVE_D: moveCat('D'); break; case Utils.InstructionType.GRAB_U: StartCoroutine(grabCat('U')); break; case Utils.InstructionType.GRAB_L: StartCoroutine(grabCat('L')); break; case Utils.InstructionType.GRAB_R: StartCoroutine(grabCat('R')); break; case Utils.InstructionType.GRAB_D: StartCoroutine(grabCat('D')); break; case Utils.InstructionType.WAIT: waitCat(); if (!catIsWaiting) { continue; } break; } if (!catIsWaiting) { catNextStep(); } } if (dogIndex < dogInstructionList.list.Count) { switch (dogAction) { case Utils.InstructionType.MOVE_U: moveDog('U'); break; case Utils.InstructionType.MOVE_L: moveDog('L'); break; case Utils.InstructionType.MOVE_R: moveDog('R'); break; case Utils.InstructionType.MOVE_D: moveDog('D'); break; case Utils.InstructionType.GRAB_U: StartCoroutine(grabDog('U')); break; case Utils.InstructionType.GRAB_L: StartCoroutine(grabDog('L')); break; case Utils.InstructionType.GRAB_R: StartCoroutine(grabDog('R')); break; case Utils.InstructionType.GRAB_D: StartCoroutine(grabDog('D')); break; case Utils.InstructionType.WAIT: waitDog(); if (!dogIsWaiting) { continue; } break; } if (!dogIsWaiting) { dogNextStep(); } } if (catIsWaiting && dogIndex >= dogInstructionList.list.Count) { missionFailed = true; missionResult = MissionResult.Condition.CAT_WAITING_FAIL; break; } if (dogIsWaiting && catIndex >= catInstructionList.list.Count) { missionFailed = true; missionResult = MissionResult.Condition.DOG_WAITING_FAIL; break; } yield return(new WaitForSeconds(secondsPerMove + secondsBetweenMoves)); } yield return(new WaitForSeconds(1f)); if (!missionFailed) { missionResult = MissionResult.checkMissionResult(puzzleManager, catIsHoldingKind, dogIsHoldingKind); if (missionResult != MissionResult.Condition.SUCCESS) { missionFailed = true; } } endMenu.SetActive(true); foreach (Text child in endMenu.GetComponentsInChildren <Text>()) { if (child.name == "ResultText") { child.text = MissionResult.conditionNames[missionResult]; } } if (missionResult == MissionResult.Condition.SUCCESS) { SaveManager.SetFinishedMap(PuzzleManager.stageInfo.name.Substring("PuzzleStage".Length)); } isInterpreting = false; yield break; }