use of com.badlogic.gdx.Preferences in project AnotherMonekyParadox by SantiagoMille.
the class PantallaEasterEgg method show.
@Override
public void show() {
crearElementos();
musicPantalla.setLooping(true);
Preferences prefs = Gdx.app.getPreferences("AnotherMonkeyPreferenceStory");
if (prefs.getBoolean("music", true)) {
musicPantalla.play();
}
Gdx.input.setCatchBackKey(true);
}
use of com.badlogic.gdx.Preferences in project AnotherMonekyParadox by SantiagoMille.
the class NivelGenerico method escribirScore.
protected void escribirScore(boolean isStoryMode) {
Preferences prefs;
if (isStoryMode) {
prefs = Gdx.app.getPreferences("AnotherMonkeyPreferenceStory");
} else {
prefs = Gdx.app.getPreferences("AnotherMonkeyPreferenceSurvival");
}
String scoresString = prefs.getString("highscores", null);
String[] scores;
if (scoresString == null) {
scores = new String[0];
} else {
scores = scoresString.split(",");
}
int puntosActuales;
int puntosSiguientes;
if (scores.length >= 6) {
ArrayList<String> temp = new ArrayList<String>();
temp.addAll(Arrays.asList(scores));
for (int i = scores.length - 1; i > 0; i--) {
puntosActuales = Integer.parseInt(scores[i].split(":")[1]);
puntosSiguientes = 0;
try {
puntosSiguientes = Integer.parseInt(scores[i - 1].split(":")[1]);
} catch (Exception e) {
puntosActuales = 100000;
}
if (puntosJugador > puntosActuales && puntosJugador <= puntosSiguientes) {
Date date = new Date(TimeUtils.millis());
String dateString = new SimpleDateFormat("MM-dd-yyyy").format(date).toString();
temp.add(i, dateString + ":" + puntosJugador + "");
temp.remove(temp.size() - 1);
// scores[i] = dateString + ":" + puntosJugador + "";
}
}
StringBuilder sb = new StringBuilder();
for (String s : temp) {
sb.append(s);
sb.append(",");
}
prefs.putString("highscores", sb.toString());
prefs.flush();
} else {
ArrayList<String> temp = new ArrayList<String>();
temp.addAll(Arrays.asList(scores));
for (int i = scores.length - 1; i > 0; i--) {
puntosActuales = Integer.parseInt(scores[i].split(":")[1]);
try {
puntosSiguientes = Integer.parseInt(scores[i - 1].split(":")[1]);
} catch (Exception e) {
puntosSiguientes = 100000;
}
if (puntosJugador > puntosActuales && puntosJugador < puntosSiguientes) {
Date date = new Date(TimeUtils.millis());
String dateString = new SimpleDateFormat("MM-dd-yyyy").format(date).toString();
temp.add(i, dateString + ":" + puntosJugador + "");
// scores[i] = dateString + ":" + puntosJugador + "";
}
}
if (scores.length == 0) {
temp.add("Sometime in the paradox:1000000");
}
if (scores.length == 1) {
Date date = new Date(TimeUtils.millis());
String dateString = new SimpleDateFormat("MM-dd-yyyy").format(date).toString();
temp.add(dateString + ":" + puntosJugador + "");
} else {
Date date = new Date(TimeUtils.millis());
String dateString = new SimpleDateFormat("MM-dd-yyyy").format(date).toString();
temp.add(dateString + ":" + puntosJugador + "");
}
StringBuilder sb = new StringBuilder();
for (String s : temp) {
sb.append(s);
sb.append(",");
}
prefs.putString("highscores", sb.toString());
prefs.flush();
}
}
use of com.badlogic.gdx.Preferences in project AnotherMonekyParadox by SantiagoMille.
the class PantallaScoresSurvival method crearMenu.
@Override
void crearMenu() {
super.stageMenu = new Stage(vista);
title = new Texto(1, 1, 1);
imgBackground = new Texture("logros.png");
spriteBackground = new Sprite(imgBackground);
spriteBackground.setPosition(0, 0);
spriteBackground.setAlpha(0.7f);
Skin skin = new Skin(Gdx.files.internal("skin/comic-ui.json"));
Preferences prefs = Gdx.app.getPreferences("AnotherMonkeyPreferenceSurvival");
String names = prefs.getString("names", null);
if (names == null) {
// prefs.putString("names", "Astro");
names = "Astro,";
}
String scores = prefs.getString("highscores", null);
if (scores == null) {
// prefs.putString("highscores", "10000");
scores = "10000,";
}
Table table = new Table(skin);
table.defaults().pad(10f);
table.setFillParent(true);
table.setPosition(table.getX(), table.getY() + 250);
/**
* Se hace el titulo de scores
*/
/**
* Se crean las columnas con puntuajes
*/
Label columnName;
Label columnScore;
String[] allScores = scores.split(",");
String[] allNames = names.split(",");
int i = 0;
table.row();
for (String name : allNames) {
columnName = new Label(name + ": ", skin);
columnName.setFontScale(3f, 3f);
table.add(columnName);
columnScore = new Label(allScores[i], skin);
columnScore.setFontScale(3f, 3f);
table.add(columnScore);
i++;
table.row();
}
// Boton Return
TextureRegionDrawable trdReturn = new TextureRegionDrawable(new TextureRegion(new Texture("go-back.png")));
ImageButton btnReturn = new ImageButton(trdReturn);
btnReturn.setPosition(30, ALTO - 30 - btnReturn.getHeight());
// Click en boton Return
btnReturn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
main.setScreen(new PantallaMenu(main));
}
});
stageMenu.addActor(table);
stageMenu.addActor(btnReturn);
Gdx.input.setInputProcessor(stageMenu);
}
Aggregations