windows phone - C# IsolatedStorage problems -
i developing game windows phone using c# xna. unfortunately, xna's storage not supported on windows phone have use c# isolatedstorage, not familiar with. trying make player high score, if players score higher last high score program writes score file stored on device , every time player opens game, high score loaded file , shown them. game seems work fine, tells player have beaten last high score when exit game , run again, high score displayed zero. bug has been killing me. have tried last resort on here.
here class deals storage:
using system; using system.collections.generic; using system.linq; using system.text; using system.io.isolatedstorage; using system.io; using microsoft.xna.framework.graphics; using microsoft.xna.framework; namespace square_eyes { class rrsavescore { public string highscoreconverted; public int highscore; public rrsavescore() { highscoreconverted = highscore.tostring(); } public void writescore(rrscore score, gametime gametime) { isolatedstoragefile filestorage = isolatedstoragefile.getuserstoreforapplication(); streamwriter filewriter = new streamwriter (new isolatedstoragefilestream("newtext.txt", filemode.openorcreate,filestorage)); highscore = score.score; filewriter.writeline(highscore.tostring()); filewriter.close(); } public void readscore() { isolatedstoragefile filestorage = isolatedstoragefile.getuserstoreforapplication(); streamreader filereader = null; try { filereader = new streamreader(new isolatedstoragefilestream ("newtext.txt", filemode.open, filestorage)); highscoreconverted = filereader.readline(); filereader.close(); } catch { highscoreconverted = "0"; } } } }
here happens in main game class:
if (score.score > savescore.highscore) { savescore.writescore(score, gametime); savescore.readscore(); }
here draw method:
spritebatch.drawstring(font, savescore.highscoreconverted, new vector2(100, 100), color.white);
i need done, appreciated.
Comments
Post a Comment