free.hacknet.game.HackNetTestsMain.java Source code

Java tutorial

Introduction

Here is the source code for free.hacknet.game.HackNetTestsMain.java

Source

/*
 * This file is part of HackNet
 * Copyright (C) <2014>  <Ivan Kulikov>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package free.hacknet.game;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.FPSLogger;

import free.hacknet.game.tests.ListTestsScreen;

public class HackNetTestsMain extends ApplicationAdapter {
    private FPSLogger fpsLogger;
    private Screen curScreen; // the current screen
    private static HackNetTestsMain instance = new HackNetTestsMain();

    private HackNetTestsMain() {

    }

    public static HackNetTestsMain getInstance() {
        return instance;
    }

    @Override
    public void create() {
        Gdx.app.setLogLevel(Application.LOG_DEBUG);
        Assets.init();
        fpsLogger = new FPSLogger();
        setCurScreen(new ListTestsScreen());
    }

    public void setCurScreen(Screen s) {
        if (this.curScreen != null) {
            this.curScreen.hide();
            this.curScreen.dispose();
        }
        this.curScreen = s;
        this.curScreen.show();
    }

    @Override
    public void resize(int width, int height) {
        if (curScreen != null)
            curScreen.resize(width, height);
    }

    @Override
    public void render() {
        fpsLogger.log();
        if (curScreen != null)
            curScreen.render(Gdx.graphics.getDeltaTime());
    }

    @Override
    public void pause() {
        if (curScreen != null)
            curScreen.pause();
    }

    @Override
    public void resume() {
        if (curScreen != null)
            curScreen.resume();
    }

    @Override
    public void dispose() {
        curScreen.dispose();
    }

}