public void onRankedClick() { GameManager.gameType = "ranked"; LevelManager.difficulty = LevelUtility.calculateRankedDifficulty(); LevelManager.level = LevelUtility.calculateRankedLevel(); GameManager.Load("Game"); }
void Start() { time = 0; newScore = LevelUtility.calculateStarScore(); int level = LevelUtility.calculateIndex(LevelManager.level) - 1; int currentBest = GameManager.currentBest; int currentScore = GameManager.currentStars[level]; // New High Score OR New Best Move Solution if (newScore > currentScore || (currentBest == 0 || currentBest > LevelManager.moves.Count)) { GameManager.currentBest = (currentBest == 0 || currentBest > LevelManager.moves.Count) ? LevelManager.moves.Count : currentBest; GameManager.currentStars[level] = newScore > currentScore ? newScore : currentScore; GameManager.totalStars += (newScore - currentScore); GameManager.saveLevelScore(GameManager.currentBest, GameManager.currentStars[level]); } // On New High Score, give hints if (newScore > currentScore && newScore == 3) { GameManager.playerHints += 1; GameManager.savePlayerDetails(); } this.gameObject.transform.GetChild(0).gameObject.GetComponent <Text>().text = getSuccessText(newScore); }
public static void SaveLevelTimeRecordToPlayerPrefs(object scoredTime) { string levelName = LevelUtility.GetCurrentLevelName(); PlayerPrefs.SetFloat(levelName, (float)scoredTime); PlayerPrefs.Save(); }
public void onRetryClick() { LevelManager.time = 0; LevelManager.currentSolved = 0; LevelManager.paused = false; LevelManager.level = LevelUtility.calculateTimeTrialLevel(); GameManager.Load("Game"); }
public void onDifficultyClick(string difficulty) { LevelManager.difficulty = difficulty; LevelManager.currentSolved = 0; LevelManager.time = 0; LevelManager.level = LevelUtility.calculateTimeTrialLevel(); GameManager.Load("Game"); }
public static void UnlockNextLevel() { string nextLevelName = LevelUtility.GetNextLevelName(); if (nextLevelName != "No More Levels") { SaveManager.SaveLevelUnlocked(nextLevelName); } }
public static bool IsNextLevelUnlocked() { string nextLevelName = LevelUtility.GetNextLevelName(); if (nextLevelName != "No More Levels") { return(SaveManager.CheckIfLevelIsUnlocked(nextLevelName)); } return(false); }
public void UpdateInstance(CellView view, Vector2Int coords, CellStatusFlags cellStatus) { if (view == null) { return; } bool isRevealed = cellStatus.HasFlag(CellStatusFlags.IsRevealed); bool isMarked = !isRevealed && cellStatus.HasFlag(CellStatusFlags.IsMarked); view.textMesh.enabled = isRevealed; view.ToggleFlag(isMarked); SetCellBackground(view, isRevealed, isMarked); if (isMarked) { view.FlagColor = colorSheet.flagColor; } if (isRevealed) { if (cellStatus.HasFlag(CellStatusFlags.HasMine)) { SetMineMode(view, true); } else { SetMineMode(view, false); const int neighborCount = 8; var neighbors = ArrayPool <Vector2Int> .Get(neighborCount); LevelUtility.GetAdjacentCellsSquare(coords, neighbors); int cellValue = 0; for (int i = 0; i < neighborCount; ++i) { var neighborStatus = levelDataManager.GetCellStatus(neighbors[i]); if (neighborStatus.HasFlag(CellStatusFlags.HasMine)) { cellValue++; } } ArrayPool <Vector2Int> .Release(neighbors); view.textMesh.text = cellValue == 0 ? "" : cellValue.ToString(); view.textMesh.color = colorSheet.GetColorForCellValue(cellValue); } } else { view.mineSprite.enabled = false; } }
private int getParTime() { // If Transcendent, begin calculating actual ranked score by slowly lowering time to complete if (GameManager.rankedExperience > 5000) { int handicap = Mathf.FloorToInt((GameManager.rankedExperience - 5000) / 10); return(PAR_TIME[19] - handicap); } int complexity = Int32.Parse(LevelUtility.calculateRankedLevel().Split('_')[0]); return(PAR_TIME[complexity]); }
// Start is called before the first frame update void Start() { GameState = State.Idle; grid = GameObject.Find("Grid").GetComponent <GridComponent>(); inventory = Inventory.instance; OnNewObjectPlaced += grid.RecalculatePathAfterPlacement; OnObjectDestroyed += grid.RecalculatePathAfterDestroy; levelData = LevelUtility.GetLevelData(level); LevelUtility.LoadLevel(grid, levelData); grid.CalculatePath(); SpawnEnemy(); CheckUniqueBuildingIds(); }
void Start() { if (GameManager.gameType == "ranked") { this.gameObject.GetComponent <TextMeshProUGUI>().text = "Ranked"; } else if (GameManager.gameType == "time_trials") { this.gameObject.GetComponent <TextMeshProUGUI>().text = "Time Trials"; } else { this.gameObject.GetComponent <TextMeshProUGUI>().text = ("Level " + LevelUtility.calculateIndex(LevelManager.level)).ToString(); } }
// Use this for initialization void Start() { if (GameManager.gameType == "ranked" || GameManager.gameType == "time_trials") { Destroy(this.gameObject.transform.parent.gameObject); return; } int level = LevelUtility.calculateIndex(LevelManager.level); for (int i = 0; i < GameManager.currentStars[level - 1]; i++) { this.gameObject.transform.GetChild(i).gameObject.SetActive(true); } }
public static bool CheckIfLevelIsUnlocked(string levelName) { if (levelName == LevelUtility.GetAvailableLevels()[0]) { return(true); } string key = string.Format(PlayerPrefsKey.LevelUnlockedKey, levelName); if (PlayerPrefs.HasKey(key)) //If key exist, it always means player has unlocked this level, no need other check { return(true); } return(false); }
void Start() { if (GameManager.gameType == "levels") { Destroy(this.gameObject.transform.parent.gameObject); return; } if (GameManager.gameType == "ranked") { time = 0; } else if (GameManager.gameType == "time_trials") { time = LevelManager.time == 0 ? LevelUtility.getTimeTrialSecondsToComplete() + 1 : LevelManager.time; } LevelManager.paused = false; }
// Total stars per difficulty, from memory private static int[] getStars(string difficulty) { int[] stars = new int[40]; DirectoryInfo directory = new DirectoryInfo(Application.persistentDataPath); FileInfo[] files = directory.GetFiles("*.dat"); BinaryFormatter bf = new BinaryFormatter(); foreach (FileInfo f in files) { if (f.Name.Contains("levels_" + difficulty)) { FileStream file = File.Open(Application.persistentDataPath + "/" + f.Name, FileMode.Open); LevelScore levelScore = (LevelScore)bf.Deserialize(file); file.Close(); int index = LevelUtility.calculateIndex(f.Name.Replace("levels_" + difficulty, "").Replace(".dat", "")) - 1; stars[index] = levelScore.stars; } } return(stars); }
// Win condition void Update() { GameObject movingObj = MovingObject.getObject(); if (LevelManager.solved || movingObj == null) { return; } Vector3 newPos = MovingObject.getPosition(); if (movingObj.transform.position == newPos) { Vector3Int tilePos = playersAndGoal.WorldToCell(newPos); if (isCurrentShipObj() && playersAndGoal.GetTile(tilePos) == goal) { LevelManager.solved = true; if (GameManager.gameType == "ranked") { rankedSolvedModal.SetActive(true); } else if (GameManager.gameType == "levels") { puzzleSolvedModal.SetActive(true); } else if (GameManager.gameType == "time_trials") { LevelManager.currentSolved += 1; LevelManager.level = LevelUtility.calculateTimeTrialLevel(); GameManager.Load("Game"); } } playersAndGoal.SetTile(tilePos, isCurrentShipObj() ? ship : asteroid); MovingObject.setIsMoving(false); } movingObj.transform.position = Vector3.MoveTowards(movingObj.transform.position, newPos, 10000 * Time.deltaTime); }
private void Initialize() { m_levelSelectionView.Populate(LevelUtility.GetAvailableLevels()); }
private void setTiles(string[] tiles) { // These should be children of their respective tilemap Tile northWall = Resources.Load <Tile> ("Tiles/NorthWall"); Tile eastWall = Resources.Load <Tile> ("Tiles/EastWall"); Tile southWall = Resources.Load <Tile> ("Tiles/SouthWall"); Tile westWall = Resources.Load <Tile> ("Tiles/WestWall"); // Set Grid Visibility from Settings Tile grid = Resources.Load <Tile> ("Tiles/Grid"); Color color = grid.color; color.a = GameManager.gridVisibility; grid.color = color; int boardSize = LevelUtility.calculateBoardSize(); int middleSquare = boardSize / 2; int x = 0; int y = 0; foreach (string tileString in tiles) { // Start next row if (x >= boardSize) { x = 0; y--; } // Set all but middle grid squares (ignore for Easy difficulty) if ( LevelManager.difficulty == "easy" || ((x != middleSquare && x != middleSquare - 1) || (Math.Abs(y) != middleSquare && Math.Abs(y) != middleSquare - 1)) ) { gridTilemap.SetTile(new Vector3Int(x, y, 0), grid); } // Set outer wall if (y == -boardSize + 1) { northTilemap.SetTile(new Vector3Int(x, y - 1, 0), northWall); } if (x == 0) { eastTilemap.SetTile(new Vector3Int(x - 1, y, 0), eastWall); } if (y == 0) { southTilemap.SetTile(new Vector3Int(x, y + 1, 0), southWall); } if (x == boardSize - 1) { westTilemap.SetTile(new Vector3Int(x + 1, y, 0), westWall); } int tile = Int32.Parse(tileString) % 16; if (tile == 0) { x++; continue; } if (hasWall(tile, 1) || y == 0) { northTilemap.SetTile(new Vector3Int(x, y, 0), northWall); } if (hasWall(tile, 2) || x == boardSize - 1) { eastTilemap.SetTile(new Vector3Int(x, y, 0), eastWall); } if (hasWall(tile, 4) || y == -boardSize + 1) { southTilemap.SetTile(new Vector3Int(x, y, 0), southWall); } if (hasWall(tile, 8) || x == 0) { westTilemap.SetTile(new Vector3Int(x, y, 0), westWall); } x++; } }
private static int calculateY(int tile) { return(-1 * Mathf.FloorToInt(tile / LevelUtility.calculateBoardSize())); }
private static int calculateX(int tile) { return(tile % LevelUtility.calculateBoardSize()); }
public static void LoadNextLevel() { LevelUtility.LoadNextLevel(); }
public static void ReloadCurrentLevel() { LevelUtility.LoadCurrentLevel(); }
public static string GetCurrentLevelRecordAsString() { string currentLevelName = LevelUtility.GetCurrentLevelName(); return(GetLevelRecordAsString(currentLevelName)); }
public void Restart() { LevelUtility.LoadCurrentLevel(); }
public static float GetCurrentLevelRecordAsFloat() { string currentLevelName = LevelUtility.GetCurrentLevelName(); return(GetLevelRecordAsFloat(currentLevelName)); }
public static void LoadLevel(string levelName) { LevelUtility.LoadLevel(levelName); }
private void SetLevelName() { m_levelName?.SetText(LevelUtility.GetCurrentLevelName()); }
public void onContinueClick() { LevelManager.difficulty = LevelUtility.calculateRankedDifficulty(); LevelManager.level = LevelUtility.calculateRankedLevel(); GameManager.Load("Game"); }