java - Allowing user to play only certain level's & unlocking them -


this has been giving me headache 2 days now!

i have game levels. when level selection scene loaded, check maxlevelreached int variable.

the first time user plays, maxlevelreached variable 0.

the first level = 0 when scene loaded...

 private int level = 60;    if (level >=  maxlevelreached || maxlevelreached == 0){      box.setcolor(0, 0, 0);    }  else  {      box.setcolor(0, 0.9f, 0);  } 

as see check see if level less or equal maxlevel.

so start off user should able play first level, , when completed second level unlocked. know seems simple, reason i've been struggling it.

if user clicks on level , isn't unlocked yet, how test start level or not..

log.e("level:"+levelclicked, "level");  if(levelclicked >= maxlevelreached){                                                                levelclicked = leveltoload;         intent intent = new intent(level.this, gamelevel.class);                             intent.putextra("level", levelclicked);                                               startactivity(intent);                                                          } 

this isn't working either... reason of levels playable when should first level begin with.

here how unlock levels once previous level completed..

int currentlevel = level+1; log.e("current level unlocked", string.valueof(currentlevel)); editor.putint("max_level",currentlevel); editor.commit(); 

then in level selector scene...

int unlockedlevel = preference.getint("max_level",0); maxlevelreached += unlockedlevel; 

i know seems mess. indeed believe giving me headache. me out please?

i think comparison wrong.

if (level >=  maxlevelreached || maxlevelreached == 0) 

this reads, if level user on greater max level reached or max level reached level 0 allow.

so should < instead.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -