Allow store hiscore

This commit is contained in:
Victor 2014-01-15 14:58:54 +02:00
parent a48a4b0f8d
commit 402178eefa
2 changed files with 19 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package com.annimon.influencexxii;
import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
@ -16,6 +17,7 @@ public class InfluenceXXII implements ApplicationListener {
private BitmapFont font; private BitmapFont font;
private SpriteBatch spriteBatch; private SpriteBatch spriteBatch;
private Color background; private Color background;
private Preferences prefs;
@Override @Override
public void create() { public void create() {
@ -28,6 +30,10 @@ public class InfluenceXXII implements ApplicationListener {
spriteBatch = new SpriteBatch(); spriteBatch = new SpriteBatch();
background = DrawUtils.random2Color(0, 0x22); background = DrawUtils.random2Color(0, 0x22);
// Init preferences
prefs = Gdx.app.getPreferences("influencexxii");
Score.init(prefs);
pointer = new Pointer(width, height); pointer = new Pointer(width, height);
enemies = new EnemiesController(); enemies = new EnemiesController();
enemies.setScreenParameters(width, height); enemies.setScreenParameters(width, height);
@ -40,6 +46,8 @@ public class InfluenceXXII implements ApplicationListener {
@Override @Override
public void dispose() { public void dispose() {
Score.dispose(prefs);
prefs.flush();
renderer.dispose(); renderer.dispose();
font.dispose(); font.dispose();
spriteBatch.dispose(); spriteBatch.dispose();

View File

@ -1,5 +1,6 @@
package com.annimon.influencexxii; package com.annimon.influencexxii;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -9,8 +10,16 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
*/ */
public class Score { public class Score {
private static int killCount = 0; private static int killCount, hiscore;
private static int hiscore = 0;
public static void init(Preferences prefs) {
killCount = 0;
hiscore = prefs.getInteger("hiscore", 0);
}
public static void dispose(Preferences prefs) {
prefs.putInteger("hiscore", hiscore);
}
public static void reset() { public static void reset() {
killCount = 0; killCount = 0;