public void squareHoverOn(GameObject square, PointerEventData data) { squareController controller = square.GetComponent <squareController>(); Transform largeSquare = board.transform.GetChild(controller.row).GetChild(controller.column); if (controller.valid) { if (controller.wonBy == 0) { controller.squareHoverOn(square); if (turn == 1) { largeSquare.GetComponent <Image>().color = twoHighlightSquareColour; } else { largeSquare.GetComponent <Image>().color = oneHighlightSquareColour; } } } }
public void newLevel() //Do this every time we go to a new level { Debug.Log("newLevel():" + Time.frameCount); //Grab the square controller cuz we're gonna need to reset the squares squareController squareScript = square.GetComponent <squareController>(); //Grab the instruction square controller cuz we're gonna need to change //its sound depending on the level instructionSquareController instructionSquareScript = instructionSquare.GetComponent <instructionSquareController>(); if (currentLevel == 15) { //If we're on level 15 we need a slightly different position playerMoveTo = new Vector3(5f, 0f, -.15f); Debug.Log("15"); } else if (myDirection == "LEFT") { //If we leave from left, spawn on right playerMoveTo = new Vector3(5f, 1f, -.15f); Debug.Log("LEFT"); } else if (myDirection == "RIGHT") { //If we leave from right, come in on left playerMoveTo = new Vector3(-4f, 1f, -.15f); Debug.Log("RIGHT"); } else if (myDirection == "UP") { //If we leave from top, spawn on bottom playerMoveTo = new Vector3(1f, -1f, -.15f); Debug.Log("UP"); } else if (myDirection == "DOWN") { //If we leave from bottom, spawn on top playerMoveTo = new Vector3(1f, 3f, -.15f); Debug.Log("DOWN"); } //The z is -.15 so they're in front of everything youScript.transform.position = playerMoveTo; //Record the spot the player needs to move to so that we can do it after/while the camera moves //We do this at the top before we change myDirection to the correct direction for the next level /* * if (currentLevel == 15) * { * //If we're on level 15 we need a slightly different position * playerMoveTo = new Vector3(5f, 0f, -.15f); * Debug.Log("15"); * } * else if (myDirection == "LEFT") * { * //If we leave from left, spawn on right * playerMoveTo = new Vector3(5f, 1f, -.15f); * Debug.Log("LEFT"); * } * else if (myDirection == "RIGHT") * { * //If we leave from right, come in on left * playerMoveTo = new Vector3(-5f, 1f, -.15f); * Debug.Log("RIGHT"); * } * else if (myDirection == "UP") * { * //If we leave from top, spawn on bottom * playerMoveTo = new Vector3(1f, -1f, -.15f); * Debug.Log("UP"); * } * else if (myDirection == "DOWN") * { * //If we leave from bottom, spawn on top * playerMoveTo = new Vector3(1f, 3f, -.15f); * Debug.Log("DOWN"); * } */ //Camera stuff /* * if (firstLevelLoad == false) * { * * firstLevelLoad = true; * } else { * if (myDirection == "LEFT") * { * mainCamera.transform.position = new Vector3(16.5f, 1f, -10f); * } * else if (myDirection == "RIGHT") * { * mainCamera.transform.position = new Vector3(-15.5f, 1f, -10f); * } * else if (myDirection == "UP") * { * mainCamera.transform.position = new Vector3(0.5f, -9f, -10f); * } * else if (myDirection == "DOWN") * { * mainCamera.transform.position = new Vector3(0.5f, 11f, -10f); * } * } */ readyForCameraSwitch = true; //If we've already solved the main puzzle if (mainDoorOpened[currentLevel]) { //We have played the level completion sound doorOpenPlayed = true; //The door should already be enterable timeToDoorChange = 5; //we have completed the level levelCompleted = true; //Thus we are ready for a level change readyForLevelChange = true; //But we should not get rid of the squares goodbyeSquares = false; squaresDestroyed = 0; timeForLevelChange = false; // or reset our color mySpriteRenderer.color = openDoorColor; //If not, } else { //We haven't played the level completion sound doorOpenPlayed = false; //The door needs to wait until all sound stops before becoming enterable timeToDoorChange = 0; //if we have not already completed this level //We have not completed this new level levelCompleted = false; //Thus we are not ready for a level change readyForLevelChange = false; //Thus we should not get rid of the squares goodbyeSquares = false; squaresDestroyed = 0; timeForLevelChange = false; //Reset our color mySpriteRenderer.color = closedDoorColor; } playerMoved = false; bool spawnInstructionSquare = true; //Depending on what level we're on if (currentLevel == 0) { //If we're at level 0 this is a problem so reset to level 12 currentLevel = 12; //reset our map position to level 12 mapPosition[0] = 11; mapPosition[1] = 9; Debug.Log("Oops! You're on level 0! Probably should fix that, buddy!"); } if (currentLevel == 1) { setColorPalette(ColorPalette5); //Make the instruction square play the correct sound for the solution instructionSquareScript.mySound = level1Solution; //Set the square's position arrays to that of the correct level squareX = squareXPositionSmall; squareY = squareYPositionSmall; correctSquare = level1SquareOrder; correctSquarePlayed = new bool[level1SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareX.Length]; myDirection = "RIGHT"; } else if (currentLevel == 2) { setColorPalette(ColorPalette4); instructionSquareScript.mySound = level2Solution; squareX = squareXPositionSmall; squareY = squareYPositionSmall; correctSquare = level2SquareOrder; correctSquarePlayed = new bool[level2SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionSmall.Length]; makeSmallDoor("LEFT", levelNullSquareOrder, "", true); myDirection = "RIGHT"; } else if (currentLevel == 3) { setColorPalette(ColorPalette3); instructionSquareScript.mySound = level3Solution; squareX = squareXPositionMedium; squareY = squareYPositionMedium; correctSquare = level3SquareOrder; correctSquarePlayed = new bool[level3SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionMedium.Length]; makeSmallDoor("LEFT", levelNullSquareOrder, "", true); myDirection = "DOWN"; } else if (currentLevel == 4) { setColorPalette(ColorPalette2); instructionSquareScript.mySound = level4Solution; squareX = squareXPositionMedium; squareY = squareYPositionMedium; correctSquare = level4SquareOrder; correctSquarePlayed = new bool[level4SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionMedium.Length]; makeSmallDoor("UP", levelNullSquareOrder, "", true); if (secretDoorOpened[0]) { makeSmallDoor("LEFT", level7SquareOrder, "", true); } else { makeSmallDoor("LEFT", level7SquareOrder, "", false); } if (mainDoorOpened[7]) { makeSmallDoor("RIGHT", levelNullSquareOrder, "", true); } else { makeSmallDoor("RIGHT", levelNullSquareOrder, "", false); } myDirection = "DOWN"; } else if (currentLevel == 5) { setColorPalette(ColorPalette1); instructionSquareScript.mySound = level5Solution; squareX = squareXPositionMedium; squareY = squareYPositionMedium; correctSquare = level5SquareOrder; correctSquarePlayed = new bool[level5SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionMedium.Length]; makeSmallDoor("UP", levelNullSquareOrder, "", true); myDirection = "RIGHT"; } else if (currentLevel == 6) { setColorPalette(ColorPalette5); instructionSquareScript.mySound = level6Solution; squareX = squareXPositionMedium; squareY = squareYPositionMedium; correctSquare = level6SquareOrder; correctSquarePlayed = new bool[level6SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionMedium.Length]; makeSmallDoor("LEFT", levelNullSquareOrder, "", true); myDirection = "UP"; } else if (currentLevel == 7) { setColorPalette(ColorPalette4); instructionSquareScript.mySound = level7Solution; squareX = squareXPositionMedium; squareY = squareYPositionMedium; correctSquare = level7SquareOrder; correctSquarePlayed = new bool[level7SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionMedium.Length]; makeSmallDoor("DOWN", levelNullSquareOrder, "", true); myDirection = "LEFT"; } else if (currentLevel == 8) { setColorPalette(ColorPalette3); instructionSquareScript.mySound = level8Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level8SquareOrder; correctSquarePlayed = new bool[level8SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("RIGHT", levelNullSquareOrder, "", true); myDirection = "LEFT"; } else if (currentLevel == 9) { setColorPalette(ColorPalette2); instructionSquareScript.mySound = level9Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level9SquareOrder; correctSquarePlayed = new bool[level9SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("RIGHT", levelNullSquareOrder, "", true); myDirection = "LEFT"; } else if (currentLevel == 10) { setColorPalette(ColorPalette1); instructionSquareScript.mySound = level10Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level10SquareOrder; correctSquarePlayed = new bool[level10SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("RIGHT", levelNullSquareOrder, "", true); if (secretDoorOpened[1]) { makeSmallDoor("UP", level13SquareOrder, "", true); } else { makeSmallDoor("UP", level13SquareOrder, "", false); } myDirection = "DOWN"; } else if (currentLevel == 11) { setColorPalette(ColorPalette5); instructionSquareScript.mySound = level11Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level11SquareOrder; correctSquarePlayed = new bool[level11SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("UP", levelNullSquareOrder, "", true); myDirection = "DOWN"; } else if (currentLevel == 12) { setColorPalette(ColorPalette4); instructionSquareScript.mySound = level12Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level12SquareOrder; correctSquarePlayed = new bool[level12SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("UP", levelNullSquareOrder, "", true); myDirection = "RIGHT"; } else if (currentLevel == 13) { setColorPalette(ColorPalette3); instructionSquareScript.mySound = level13Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level13SquareOrder; correctSquarePlayed = new bool[level13SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; myDirection = "LEFT"; } else if (currentLevel == 14) { setColorPalette(ColorPalette2); instructionSquareScript.mySound = level14Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level14SquareOrder; correctSquarePlayed = new bool[level14SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("DOWN", levelNullSquareOrder, "", true); myDirection = "UP"; } else if (currentLevel == 15) { setColorPalette(ColorPalette1); spawnInstructionSquare = false; instructionSquareScript.mySound = level15Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level15SquareOrder; correctSquarePlayed = new bool[level15SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; myDirection = "DOWN"; } else if (currentLevel == 16) { instructionSquareScript.mySound = level15Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level16SquareOrder; correctSquarePlayed = new bool[level16SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; makeSmallDoor("DOWN", levelNullSquareOrder, "", true); myDirection = "UP"; } else if (currentLevel == 17) { instructionSquareScript.mySound = level15Solution; squareX = squareXPositionBig; squareY = squareYPositionBig; correctSquare = level17SquareOrder; correctSquarePlayed = new bool[level17SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionBig.Length]; } else if (currentLevel == 21) { setColorPalette(ColorPalette3); instructionSquareScript.mySound = level2Solution; squareX = squareXPositionSmall; squareY = squareYPositionSmall; correctSquare = level2SquareOrder; correctSquarePlayed = new bool[level2SquareOrder.Length]; currentCorrectSquareIndex = 0; nextSquareInCorrectOrder = correctSquare[currentCorrectSquareIndex]; squarePlayed = new bool[squareXPositionSmall.Length]; makeSmallDoor("LEFT", levelNullSquareOrder, "", true); myDirection = "RIGHT"; } //Make the squares for (int x = 0; x < squareX.Length; x++) { squareScript.mySound = musicBits[x]; squareScript.myNumber = x; Instantiate(square, new Vector3(squareX[x], squareY[x], 0f), Quaternion.identity); } //if our level has an instruction square, spawn it if (spawnInstructionSquare) { //always make the instruction square on the left side of the screen Instantiate(instructionSquare, new Vector3(-3f, 1f, 0f), Quaternion.identity); } Vector3 pos; pos = transform.position; Vector3 size = transform.localScale; //Move us to the correct location if (myDirection == "RIGHT") { pos = new Vector3(7.15f, 1f, 0f); size = new Vector3(1f, 3f, 1f); myTextMesh.transform.localScale = new Vector3(1f, 0.33f, 1f); myOutline.transform.localScale = new Vector3(1.1f, 1.03f, 1f); } else if (myDirection == "LEFT") { pos = new Vector3(-6.16f, 1f, 0f); size = new Vector3(1f, 3f, 1f); myTextMesh.transform.localScale = new Vector3(1f, 0.33f, 1f); myOutline.transform.localScale = new Vector3(1.1f, 1.03f, 1f); } else if (myDirection == "UP") { pos = new Vector3(1f, 6f, 0f); size = new Vector3(3f, 1f, 1f); myTextMesh.transform.localScale = new Vector3(0.33f, 1f, 1f); myOutline.transform.localScale = new Vector3(1.03f, 1.1f, 1f); } else if (myDirection == "DOWN") { pos = new Vector3(1f, -4f, 0f); size = new Vector3(3f, 1f, 1f); myTextMesh.transform.localScale = new Vector3(0.33f, 1f, 1f); myOutline.transform.localScale = new Vector3(1.03f, 1.1f, 1f); } transform.position = pos; transform.localScale = size; }
public void squareClicked(GameObject square, PointerEventData data) { // Check validity and perform 'taking' action squareController controller = square.GetComponent <squareController>(); if (square.GetComponent <squareController>().valid) { if (turn == 1) { turn++; controller.setWinState(1); } else { turn--; controller.setWinState(2); } // Move highlight to new large square foreach (Transform row in board.transform) { foreach (Transform largeSquare in row) { if (square.transform.IsChildOf(largeSquare)) { lastHighlight = largeSquare; } } } // Check winning conditions if (lastHighlight) { //print("checking for win at (" + lastHighlight.GetComponent<squareController>().row + ", " + lastHighlight.GetComponent<squareController>().column + ")"; // Check win within a large square List <List <int> > squareStateList = new List <List <int> >(); for (int row = 0; row < lastHighlight.GetChild(0).childCount; row++) { List <int> sublist = new List <int>(); for (int child = 0; child < lastHighlight.GetChild(0).GetChild(row).childCount; child++) { sublist.Add(lastHighlight.GetChild(0).GetChild(row).GetChild(child).GetComponent <squareController>().wonBy); } squareStateList.Add(sublist); } int smallSquareWin = checkWin(squareStateList); if (smallSquareWin != 0) { lastHighlight.GetComponent <squareController>().setWinState(smallSquareWin); destroyChildren(lastHighlight.gameObject); } // Check win for whole board List <List <int> > largeSquareStateList = new List <List <int> >(); for (int row = 0; row < board.transform.childCount; row++) { List <int> sublist = new List <int>(); for (int child = 0; child < board.transform.GetChild(row).childCount; child++) { sublist.Add(board.transform.GetChild(row).GetChild(child).GetComponent <squareController>().wonBy); } largeSquareStateList.Add(sublist); } int largeSquareWin = checkWin(largeSquareStateList); // Handle win - TEMP if (largeSquareWin != 0) { win(largeSquareWin); } } // Do highlight updating // If new square is different if (lastHighlight != board.transform.GetChild(square.GetComponent <squareController>().row).GetChild(square.GetComponent <squareController>().column)) { // Set current large square to invalid and get new square, setting it to valid lastHighlight.GetComponent <squareController>().setLargeSquareValidity(false); lastHighlight = board.transform.GetChild(square.GetComponent <squareController>().row).GetChild(square.GetComponent <squareController>().column); lastHighlight.GetComponent <squareController>().setLargeSquareValidity(true); } // Otherwise can stay as-is // Update valid squares // If the square isn't won if (lastHighlight.GetComponent <squareController>().wonBy == 0) { // Set only new square's subsquares as valid - if they aren't won yet setSmallAllValidity(false); setLargeAllValidity(false); lastHighlight.GetComponent <squareController>().setLargeSquareValidity(true); foreach (Transform row in lastHighlight.GetChild(0)) { foreach (Transform child in row) { if (child.GetComponent <squareController>().wonBy == 0) { child.GetComponent <squareController>().valid = true; } } } } else { // Otherwise everything is valid setSmallAllValidity(true); setLargeAllValidity(true); lastHighlight.GetComponent <Image>().color = lastHighlight.GetComponent <squareController>().currentColour; } } }