// Determine what type of GamePiece needs action and perform the action public void DetermineAction(int x, int z, CubePiece.Direction direction) { if (gamePieces[x, z].pieceType == GamePiece.PieceType.CUBE) { StartCoroutine(((CubePiece)gamePieces[x, z]).Rotate(direction, false)); } else if (gamePieces[x, z].pieceType == GamePiece.PieceType.ROTATION) { if (!GameController.GetInstance().editingLevel) { StartCoroutine(((RotationPiece)gamePieces[x, z]).Rotate(false)); } else { GameController.GetInstance().AnimateEnd(); } } else if (gamePieces[x, z].pieceType == GamePiece.PieceType.TOGGLE) { if (!GameController.GetInstance().editingLevel) { StartCoroutine(((TogglePiece)gamePieces[x, z]).Flip(false)); } else { GameController.GetInstance().AnimateEnd(); } } else { GameController.GetInstance().AnimateEnd(); } }
public void PieceClicked(GamePiece gamePiece, CubePiece.Direction direction) { if (RecordingMoves) { switch (gamePiece.pieceType) { case GamePiece.PieceType.CUBE: moveList = "C" + gamePiece.XPos + "," + gamePiece.ZPos + " " + moveList; break; case GamePiece.PieceType.ROTATION: moveList = "R" + gamePiece.XPos + "," + gamePiece.ZPos + " " + moveList; break; case GamePiece.PieceType.TOGGLE: moveList = "T" + gamePiece.XPos + "," + gamePiece.ZPos + " " + moveList; break; } Debug.Log(moveList); winMovesText.text = moveList; } }
public void PieceAction(int x, int z, bool wasCubePiece = false, CubePiece.Direction direction = CubePiece.Direction.NORTH) { if (!editingLevel && !inMenu) { movesMade++; limitText.text = "Moves: " + (mainController.GetCurrentLevel().levelLimits[2] - movesMade).ToString(); } int tempX = x; int tempZ = z + 1; for (int i = 0; i < 4; i++) { if (gameBoard.DoesPieceExist(tempX, tempZ)) { gameBoard.GetGamePiece(tempX, tempZ).pieceAnimating = true; } if (i == 0) { tempX += 1; } else { tempX -= 1; } if (i == 2) { tempZ += 1; } else { tempZ -= 1; } } UpdateNeeded = true; StartCoroutine(gameBoard.UpdatePathsAndCheckForWin(false)); StartCoroutine(gameBoard.PieceAction(x, z, wasCubePiece, direction)); }
public void LERotatePiece(int x, int z, bool mixing = false, CubePiece.Direction direction = CubePiece.Direction.NORTH) { int prefabIndex; switch (gamePieces[x, z].pieceType) { case GamePiece.PieceType.TOGGLE: if (gamePieces[x, z].GetPrefabIndex() == togglePrefabs.Length - 1) { prefabIndex = 0; } else { prefabIndex = gamePieces[x, z].GetPrefabIndex() + 1; } ReplaceGamePiece(x, z, togglePrefabs[prefabIndex]); break; case GamePiece.PieceType.ROTATION: if ((gamePieces[x, z] as RotationPiece).rotationPieceType == RotationPiece.RotationPieceType.ANGLED) { //if (gamePieces[x, z].GetPrefabIndex() == rotationAngledPrefabs.Length - 1) prefabIndex = 0; //else prefabIndex = gamePieces[x, z].GetPrefabIndex() + 1; if (gamePieces[x, z].GetPrefabIndex() == 0) { prefabIndex = rotationAngledPrefabs.Length - 1; } else { prefabIndex = gamePieces[x, z].GetPrefabIndex() - 1; } ReplaceGamePiece(x, z, rotationAngledPrefabs[prefabIndex]); } else { if (gamePieces[x, z].GetPrefabIndex() == rotationStraightPrefabs.Length - 1) { prefabIndex = 0; } else { prefabIndex = gamePieces[x, z].GetPrefabIndex() + 1; } ReplaceGamePiece(x, z, rotationStraightPrefabs[prefabIndex]); } break; case GamePiece.PieceType.CUBE: if (!mixing) { if (gamePieces[x, z].GetPrefabIndex() == cubePrefabs.Length - 1) { prefabIndex = 0; } else { prefabIndex = gamePieces[x, z].GetPrefabIndex() + 1; } ReplaceGamePiece(x, z, cubePrefabs[prefabIndex]); } else { switch (gamePieces[x, z].GetPrefabIndex()) { case 0: switch (direction) { case CubePiece.Direction.NORTH: case CubePiece.Direction.SOUTH: ReplaceGamePiece(x, z, cubePrefabs[2]); break; case CubePiece.Direction.EAST: case CubePiece.Direction.WEST: ReplaceGamePiece(x, z, cubePrefabs[1]); break; } break; case 1: switch (direction) { case CubePiece.Direction.EAST: case CubePiece.Direction.WEST: ReplaceGamePiece(x, z, cubePrefabs[0]); break; } break; case 2: switch (direction) { case CubePiece.Direction.NORTH: case CubePiece.Direction.SOUTH: ReplaceGamePiece(x, z, cubePrefabs[0]); break; } break; } } break; } StartCoroutine(UpdatePathsAndCheckForWin()); }
// Piece action was performed by player, cascade to adjacent pieces if needed public IEnumerator PieceAction(int x, int z, bool wasCubePiece, CubePiece.Direction direction) { // Perform action on adjacent GamePieces, N->E->S->W //Debug.Log("PieceAction " + x + "," + z); if (!GameController.GetInstance().editingLevel) { SoundManager.instance.PlaySingle(pieceClickClip, true); } #if UNITY_EDITOR if (GameController.GetInstance().editingLevel) { LERotatePiece(x, z, true, direction); if (wasCubePiece) { GameController.GetInstance().ActivePiece = gamePieces[x, z]; StartCoroutine((gamePieces[x, z] as CubePiece).Activate(false)); } FindObjectOfType <LevelEditor>().PieceClicked(gamePieces[x, z], direction); } #endif z = z + 1; for (int i = 0; i < 4; i++) { yield return(new WaitForSeconds(adjacentAnimWait)); // If piece exists, perform action, else decrease animation counter if (DoesPieceExist(x, z)) { #if UNITY_EDITOR if (GameController.GetInstance().editingLevel) { if (wasCubePiece) { LERotatePiece(x, z, true, direction); } else { switch (i) { case 0: LERotatePiece(x, z, true, CubePiece.Direction.NORTH); break; case 1: LERotatePiece(x, z, true, CubePiece.Direction.EAST); break; case 2: LERotatePiece(x, z, true, CubePiece.Direction.SOUTH); break; case 3: LERotatePiece(x, z, true, CubePiece.Direction.WEST); break; } } } #endif DetermineAction(x, z, direction); } else { GameController.GetInstance().AnimateEnd(); } if (!wasCubePiece) { direction++; } if (i == 0) { x += 1; } else { x -= 1; } if (i == 2) { z += 1; } else { z -= 1; } } }