package main;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import framework.component.ComponentSystem;
import framework.component.ParentComponent;
import framework.event.EventSystem;
import framework.rendering.GraphicsSystem;
import framework.timing.SystemClockComponent;
import framework.userinput.MouseListenerSystem;
public class Game extends BasicGame {
public static final String GAME_NAME = "Dots and Boxes";
public Game(){
super(GAME_NAME);
}
private SystemClockComponent clock;
@Override
public void init(GameContainer gc) throws SlickException{
initTimer();
registerInputSystems(gc);
GameLoader.loadGameWithOptionsMenu(6, 6, gc);
}
private void initTimer(){
ComponentSystem cs = ComponentSystem.getInstance();
ParentComponent root = cs.getRoot();
clock = new SystemClockComponent();
root.addComponent(clock);
}
private void registerInputSystems(GameContainer gc){
gc.getInput().addMouseListener(MouseListenerSystem.getInstance());
}
@Override
public void update(GameContainer gc, int delta) throws SlickException{
EventSystem es = EventSystem.getInstance();
while(!es.isEmpty()){
es.evaluateNextEvent();
}
clock.tick(delta);
}
@Override
public void render(GameContainer gc, Graphics g) throws SlickException{
GraphicsSystem.getInstance().render(gc, g);
}
}