java - User can do to the same level twice -


i have been working time on game. not difficult , there levels.

every time user passes level, getting point. happens user can same level several times , take on of points wants, how fix it? not along.

if not wrong, asking how make sure user doesn't point again stage have crossed/solved.

well, there simple idea. each stage keep tag (unique name) , if user have crossed stage, give him point , set tag value 1 or true, in shared-preferences. so, if user plays again same level, check tag , if , if tag unset give him score/point, otherwise don't give score/point.

this how store pair in shared preferences:

      sharedpreferences.editor editor = getsharedpreferences("my_pref_file_name", mode_private).edit();     editor.putint("level-1", "1"); //1 means cleared level     editor.commit();  

let me give sample(note make changes per need)

      int score = 0;      sharedpreferences prefs = getsharedpreferences("my_pref_file_name", mode_private);      int alreadywon = prefs.getint("level-1", -1); // function means; give me value of level-1 if exits, else return -1     if(alreadywon == 1){         // have given score         //todo -> next     }     else{         //you have not got score before level, give score of 1         score = score + 1;         //and set score of level in shared preferences         sharedpreferences.editor editor = getsharedpreferences("my_pref_file_name", mode_private).edit();         editor.putint("level-1", "1"); //1 means cleared level         editor.commit();     }  

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -