Coordinate findNextTarget(Coordinate coord, int prevExit) { Coordinate res = new Coordinate(-1, -1); Coordinate destCoord = mapCreator.getCoordinateFromExit(coord, prevExit); object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); TileScript prefabScript = tilePrefab.getTileScript(); if (prefabCoord.equals(destCoord)) { if (tilePrefab.getState() == Enums.TilePrefabState.Normal) { targetCoord.Add(prefabCoord); targetPos.Add(tilePrefab.transform.position); targetEntr.Add(getEntry(prevExit)); res = targetCoord [targetEntr.Count - 1]; tilePrefab.setState(Enums.TilePrefabState.Target); } else if (tilePrefab.getState() == Enums.TilePrefabState.Fixed) { if (prefabScript.getType() == "Finish") { res = new Coordinate(-2, -2); } else if (!(prefabScript.getType() == "Start")) { int entry = getEntry(prevExit); bool isValid = false; int exit = 0; if (prefabScript.getExits() [0] == entry) { isValid = true; exit = prefabScript.getExits() [1]; } else if (prefabScript.getExits() [1] == entry) { isValid = true; exit = prefabScript.getExits() [0]; } if (isValid) { res = findNextTarget(prefabCoord, exit); } } } } } return(res); }
void enableFirstHand() { Coordinate startTileCoordinate = mapCreator.getCompletePath() [0].getCoordinates(); object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; TileScript prefabScript = tilePrefab.getTileScript(); Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); if (tilePrefab.getState() == Enums.TilePrefabState.Blocked) { Coordinate dest1 = mapCreator.getCoordinateFromExit(targetCoord [targetCoord.Count - 1], prefabScript.getExits() [0]); Coordinate dest2 = mapCreator.getCoordinateFromExit(targetCoord [targetCoord.Count - 1], prefabScript.getExits() [1]); bool isValid = false; if (startTileCoordinate.equals(dest1)) { isValid = true; tilePrefab.getTileScript().setFreeExit(2); } else if (startTileCoordinate.equals(dest2)) { isValid = true; tilePrefab.getTileScript().setFreeExit(1); } if (isValid) { tilePrefab.getTileScript().setCoordinates(targetCoord [targetCoord.Count - 1]); tilePrefab.setState(Enums.TilePrefabState.Ready); } } } }
public void setFirstTarget(Coordinate targetCoordinate) { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); if (tilePrefab.getState() == Enums.TilePrefabState.Available) { if (targetCoordinate.equals(prefabCoord)) { targetCoord.Add(prefabCoord); targetPos.Add(tilePrefab.transform.position); tilePrefab.hover(false); tilePrefab.setState(Enums.TilePrefabState.Target); GameObject.Find("Back").GetComponent <BackScript> ().setState(Enums.SelectorState.Free); } else { tilePrefab.setState(Enums.TilePrefabState.Normal); } } } enableFirstHand(); }
//AQUI void back() { moves.RemoveAt(moves.Count - 1); object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); if (tilePrefab.getState() == Enums.TilePrefabState.Used && prefabCoord.equals(targetCoord [targetCoord.Count - 1])) { tilePrefab.moveBack(); tilePrefab.transform.Translate(new Vector3(0, 0, 5), Space.World); tilePrefab.state = Enums.TilePrefabState.Blocked; tilePrefab.setAlpha(); } } isBlocked = false; disableHand(); if (moves.Count == 0) { enableFirstHand(); } else { enableHand(); } }
public void backStep() { if (moves.Count == 0) { GameObject.Find("Back").GetComponent <BackScript> ().setState(Enums.SelectorState.Blocked); backToStart(); } else { if (!isBlocked) { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); if (tilePrefab.getState() == Enums.TilePrefabState.Target && prefabCoord.equals(targetCoord [targetCoord.Count - 1])) { tilePrefab.state = Enums.TilePrefabState.Normal; tilePrefab.setGrass(); } } targetCoord.RemoveAt(targetCoord.Count - 1); targetEntr.RemoveAt(targetEntr.Count - 1); targetPos.RemoveAt(targetPos.Count - 1); } back(); } }
void enableHand() { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); TileScript prefabScript = tilePrefab.getTileScript(); if (tilePrefab.getState() == Enums.TilePrefabState.Blocked) { bool isValid = false; if (prefabScript.getExits() [0] == targetEntr [targetEntr.Count - 1]) { isValid = true; prefabScript.setFreeExit(2); } else if (prefabScript.getExits() [1] == targetEntr [targetEntr.Count - 1]) { isValid = true; prefabScript.setFreeExit(1); } if (isValid) { tilePrefab.setState(Enums.TilePrefabState.Ready); } } } }
void placeTile() { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); TileScript prefabScript = tilePrefab.getTileScript(); if (prefabCoord.getX() == -1 && prefabCoord.getY() == -1) { tilePrefab.setOriginalPos(tilePrefab.transform.position); Vector3 newPos = targetPos [targetPos.Count - 1]; newPos.Set(targetPos [targetPos.Count - 1].x, targetPos [targetPos.Count - 1].y, tilePrefab.originalPosition.z); tilePrefab.transform.position = newPos; tilePrefab.transform.Translate(new Vector3(0, 0, -4), Space.World); prefabScript.setCoordinates(targetCoord [targetCoord.Count - 1]); tilePrefab.setState(Enums.TilePrefabState.Used); moves.Add(prefabScript); } else if (tilePrefab.getState() == Enums.TilePrefabState.Ready) { tilePrefab.setState(Enums.TilePrefabState.Blocked); } } }
void disableHand() { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); TileScript prefabScript = tilePrefab.getTileScript(); if (tilePrefab.getState() == Enums.TilePrefabState.Ready) { tilePrefab.setState(Enums.TilePrefabState.Blocked); } } }
void backToStart() { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); if (tilePrefab.getState() == Enums.TilePrefabState.Target) { tilePrefab.state = Enums.TilePrefabState.Normal; } } disableHand(); enableStartTiles(); }
public void enableStartTiles() { foreach (Coordinate coord in startTilesCoordinates) { object[] obj = GameObject.FindObjectsOfType(typeof(TilePrefabScript)); foreach (object o in obj) { TilePrefabScript tilePrefab = (TilePrefabScript)o; Coordinate prefabCoord = tilePrefab.getTileScript().getCoordinates(); if (coord.equals(prefabCoord)) { if (tilePrefab.getState() == Enums.TilePrefabState.Normal) { tilePrefab.setState(Enums.TilePrefabState.Available); } } } } }