package com.fundynamic.d2tm;

import com.fundynamic.d2tm.game.PlayingState;
import com.fundynamic.d2tm.game.TerrainFactory;
import com.fundynamic.d2tm.game.terrain.DuneTerrainFactory;
import com.fundynamic.d2tm.graphics.Theme;
import org.newdawn.slick.*;


public class Game extends BasicGame {

    private static final int SCREEN_WIDTH = 800;
    private static final int SCREEN_HEIGHT = 600;

    private PlayingState playingState;

    public Game() {
        super("Dune II - The Maker");
    }

    public void render(GameContainer container, Graphics g) throws SlickException {
        playingState.init();
        playingState.render();
    }

    @Override
    public void init(GameContainer gameContainer) throws SlickException {
        try {
            Theme theme = new Theme(new Image("sheet_terrain.png"));
            TerrainFactory terrainFactory = new DuneTerrainFactory(theme);
            playingState = new PlayingState(gameContainer, terrainFactory);
            // calling init here does not work with images
        } catch (Exception e) {
            throw new SlickException("Exception occurred while initializing game.", e);
        }
    }

    @Override
    public void update(GameContainer container, int delta) throws SlickException {
        playingState.update();
    }
    
    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new Game());
        app.setDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, false);
        app.setForceExit(true);
        app.start();
    }

}

@@ -248,16 +248,57 @@
 lick.*;%0A
+import org.newdawn.slick.util.Bootstrap;%0A
 %0A%0Apublic
@@ -486,16 +486,28 @@
 ic Game(
+String title
 ) %7B%0A    
@@ -520,29 +520,13 @@
 per(
-%22Dune II - The Maker%22
+title
 );%0A 
@@ -1334,20 +1334,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -1382,211 +1382,112 @@
 gs) 
-throws SlickException %7B%0A        AppGameContainer app = new AppGameContainer(new Game());%0A        app.setDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, false);%0A        app.setForceExit(true);%0A        app.start(
+%7B%0A        Bootstrap.runAsApplication(new Game(%22Dune II - The Maker%22), SCREEN_WIDTH, SCREEN_HEIGHT, false
 );%0A 

initialize game like before