package com.bombasticoctocat.bomberman.game;

public class Game {
    private Hero hero;
    private Board board;
    private int level = 1;
    private Timer timer;
    private Detonator detonator;

    public Game() {
        this.timer = new Timer();
        this.detonator = new Detonator(timer);
        this.hero = new Hero(detonator);
        this.board = new Board(timer, hero, detonator, Configuration.forLevel(level));
    }

    public void tick(long timeDelta, Directions directions, boolean plantBomb, boolean detonateBomb) {
        Board.State state = board.tick(timeDelta, directions, plantBomb, detonateBomb);
        if (state == Board.State.LOST) {
            hero.revive();
            board = new Board(timer, hero, detonator, Configuration.forLevel(level));
        }

        if (state == Board.State.WON) {
            hero.nextLevel();
            level++;
            board = new Board(timer, hero, detonator, Configuration.forLevel(level));
        }
    }

    public Board getBoard() {
        return board;
    }

    public int getLevel() {
        return level;
    }

    public int getLives() {
        return hero.getLives();
    }

    public boolean isLevelInProgress() {
        return true;
    }

    public boolean isOver() {
        return false;
    }

}

@@ -191,16 +191,118 @@
 tonator;
+%0A    private boolean over;%0A    private boolean won;%0A%0A    private static final long LEVEL_DELAY = 1000;
 %0A%0A    pu
@@ -446,20 +446,49 @@
        t
-his.
+imer.schedule(LEVEL_DELAY, () -%3E 
 board = 
@@ -547,24 +547,77 @@
 evel(level))
+);%0A        this.over = false;%0A        this.won = true
 ;%0A    %7D%0A%0A   
@@ -712,24 +712,119 @@
 nateBomb) %7B%0A
+        if (board == null) %7B%0A            timer.tick(timeDelta);%0A            return;%0A        %7D%0A%0A
         Boar
@@ -936,24 +936,50 @@
 ate.LOST) %7B%0A
+            board = null;%0A
             
@@ -996,32 +996,159 @@
 e();%0A           
+ if (hero.getLives() %3C 0) %7B%0A                over = true;%0A            %7D else %7B%0A                timer.schedule(LEVEL_DELAY, () -%3E
  board = new Boa
@@ -1196,34 +1196,49 @@
 forLevel(level))
+)
 ;%0A
+            %7D%0A
         %7D%0A%0A     
@@ -1268,24 +1268,50 @@
 tate.WON) %7B%0A
+            board = null;%0A
             
@@ -1352,32 +1352,179 @@
 l++;%0A           
+ if (level %3E 50) %7B%0A                board = null;%0A                won = true;%0A            %7D else %7B%0A                timer.schedule(LEVEL_DELAY, () -%3E
  board = new Boa
@@ -1580,18 +1580,33 @@
 (level))
+)
 ;%0A
+            %7D%0A
         
@@ -1853,20 +1853,29 @@
  return 
-true
+board != null
 ;%0A    %7D%0A
@@ -1920,24 +1920,67 @@
  return 
-false;%0A   
+over;%0A    %7D%0A%0A    public boolean isWon() %7B return won;
  %7D%0A%0A%7D%0A

add decent interleaves between levels