示例#1
0
 public void onRankedClick()
 {
     GameManager.gameType    = "ranked";
     LevelManager.difficulty = LevelUtility.calculateRankedDifficulty();
     LevelManager.level      = LevelUtility.calculateRankedLevel();
     GameManager.Load("Game");
 }
示例#2
0
    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);
    }
示例#3
0
        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");
 }
示例#6
0
        public static void UnlockNextLevel()
        {
            string nextLevelName = LevelUtility.GetNextLevelName();

            if (nextLevelName != "No More Levels")
            {
                SaveManager.SaveLevelUnlocked(nextLevelName);
            }
        }
示例#7
0
        public static bool IsNextLevelUnlocked()
        {
            string nextLevelName = LevelUtility.GetNextLevelName();

            if (nextLevelName != "No More Levels")
            {
                return(SaveManager.CheckIfLevelIsUnlocked(nextLevelName));
            }

            return(false);
        }
示例#8
0
        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;
            }
        }
示例#9
0
    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]);
    }
示例#10
0
 // 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();
 }
示例#11
0
 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();
     }
 }
示例#12
0
    // 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);
        }
    }
示例#13
0
        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);
        }
示例#14
0
    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;
    }
示例#15
0
    // 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);
    }
示例#16
0
    // 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);
    }
示例#17
0
 private void Initialize()
 {
     m_levelSelectionView.Populate(LevelUtility.GetAvailableLevels());
 }
示例#18
0
    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++;
        }
    }
示例#19
0
 private static int calculateY(int tile)
 {
     return(-1 * Mathf.FloorToInt(tile / LevelUtility.calculateBoardSize()));
 }
示例#20
0
 private static int calculateX(int tile)
 {
     return(tile % LevelUtility.calculateBoardSize());
 }
示例#21
0
 public static void LoadNextLevel()
 {
     LevelUtility.LoadNextLevel();
 }
示例#22
0
 public static void ReloadCurrentLevel()
 {
     LevelUtility.LoadCurrentLevel();
 }
示例#23
0
        public static string GetCurrentLevelRecordAsString()
        {
            string currentLevelName = LevelUtility.GetCurrentLevelName();

            return(GetLevelRecordAsString(currentLevelName));
        }
示例#24
0
 public void Restart()
 {
     LevelUtility.LoadCurrentLevel();
 }
示例#25
0
        public static float GetCurrentLevelRecordAsFloat()
        {
            string currentLevelName = LevelUtility.GetCurrentLevelName();

            return(GetLevelRecordAsFloat(currentLevelName));
        }
示例#26
0
 public static void LoadLevel(string levelName)
 {
     LevelUtility.LoadLevel(levelName);
 }
示例#27
0
 private void SetLevelName()
 {
     m_levelName?.SetText(LevelUtility.GetCurrentLevelName());
 }
示例#28
0
 public void onContinueClick()
 {
     LevelManager.difficulty = LevelUtility.calculateRankedDifficulty();
     LevelManager.level      = LevelUtility.calculateRankedLevel();
     GameManager.Load("Game");
 }