Search in sources :

Example 21 with Preferences

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);
}
Also used : Preferences(com.badlogic.gdx.Preferences)

Example 22 with Preferences

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();
    }
}
Also used : ArrayList(java.util.ArrayList) Preferences(com.badlogic.gdx.Preferences) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 23 with Preferences

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);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Preferences(com.badlogic.gdx.Preferences) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Preferences (com.badlogic.gdx.Preferences)23 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)7 Texture (com.badlogic.gdx.graphics.Texture)5 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)5 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)5 Bala (mx.itesm.another_monkey_paradox.Objetos.Bala)5 Enemigo (mx.itesm.another_monkey_paradox.Objetos.Enemigo)5 Granada (mx.itesm.another_monkey_paradox.Objetos.Granada)5 Fondo (mx.itesm.another_monkey_paradox.Utils.Fondo)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)4 Stage (com.badlogic.gdx.scenes.scene2d.Stage)4 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)4 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)4 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)4 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2