0

I am trying to make a puzzle game in which there are 3 Game Modes (Normal mode,Timer Mode, Taps Mode) and 50 levels. All 50 levels are same for all 3 modes but in timer timer mode there is countdown timer and and in taps mode there are both timer and taps. And in normal mode there is no restriction.

Now I am saving each level according to modes in PlayerPrefs.

I am not locking the levels at all but Timer mode and Taps Mode are locked. Only normal Mode is unlocked.

Now here is what I want. To unlock timer mode first play any 10 normal mode levels and to unlock tap mode first play any 10 timer mode levels.

How to keep track how many levels are completed.

Here is code this is how i am saving each level after completi

if (isNormalMode) {
    PlayerPrefs.SetString ("norm"+levelStr, levelStr);
    } 

if (isTimerMode) {
    PlayerPrefs.SetString ("timer"+levelStr, levelStr);
    }

if (isTapsMode) {
    PlayerPrefs.SetString ("taps"+levelStr, levelStr);
    }
Jamshaid Alam
  • 515
  • 1
  • 9
  • 24
  • This is just all wrong. Do what *Programmer* says below. It's also worth bearing in mind that, simply, *you don't make games like this any more*. to make games today is to use PubNub, Parse, Firebase or the like. Anything vaguely like what is being discussed here, would simply be a crowd-cloud feature. – Fattie Feb 19 '17 at 15:31

1 Answers1

0

You have to represent the level and level information in a class then put another class array inside that class. That class array you can use to determine which level it is with index 0 being level 1 and index 1 being level 2.

[System.Serializable]
 public class Levels
 {
     public LevelInfo[] levelInfo;
 }

 [System.Serializable]
 public class LevelInfo
 {
     public bool isCompleted;
     public string levelName;
     public int levelScore;

     //Other Level Information here
 }

Grab the DataSaver Helper class from this post.


You can then create levels (5 levels for example):

Levels levels = new Levels();
levels.levelInfo = new LevelInfo[5];

for (int i = 0; i < levels.levelInfo.Length; i++)
{
    levels.levelInfo[i] = new LevelInfo();
    levels.levelInfo[i].levelName = i + 1.ToString();
    levels.levelInfo[i].levelScore = UnityEngine.Random.Range(10, 100);
    levels.levelInfo[i].isCompleted = true;
}

Save the Levels:

DataSaver.saveData(levels, "Levels");

Load the Levels:

Load and check if levels are completed:

//Load Saved Data
Levels levels = DataSaver.loadData<Levels>("Levels");

Check if level 1 is completed.

if (levels.levelInfo[0].isCompleted)
{
    //Level 1 Completed
}

Check if level 2 is completed.

if (levels.levelInfo[1].isCompleted)
{
    //Level 2 Completed
}

....

When that is setup correctly, the proper way to read the levels is to use loop to find out which level is not yet completed then start from there.

Levels levels = DataSaver.loadData<Levels>("Levels");
for (int i = 0; i < levels.levelInfo.Length; i++)
{
    if (!levels.levelInfo[i].isCompleted)
    {
        Debug.LogFormat("Level ({0}) is not completed", i + 1);
        //Level not completed. Start from here!
    }
}
Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328