package hu.supercluster.gameoflife.game.manager;

import hu.supercluster.gameoflife.game.view.AutomatonView;
import hu.supercluster.gameoflife.game.cellularautomaton.CellularAutomaton;
import hu.supercluster.gameoflife.game.cellularautomaton.CellularAutomatonFactory;

public class GameManager {
    private static CellularAutomaton automaton;
    private final AutomatonView automatonView;
    private final GameParams params;

    public GameManager(AutomatonView automatonView, CellularAutomatonFactory factory, GameParams params) {
        this.automatonView = automatonView;
        this.params = params;

        automaton = createAutomaton(factory, params);
    }

    public void createGame() {
        initView(
                automatonView,
                automaton,
                params
        );
    }

    private static void initView(AutomatonView automatonView, CellularAutomaton automaton, GameParams params) {
        automatonView.init(
                automaton,
                params
        );
    }

    private static CellularAutomaton createAutomaton(CellularAutomatonFactory factory, GameParams params) {
        CellularAutomaton<?> automaton = factory.create(
                params.getGridSizeX(),
                params.getGridSizeY()
        );

        automaton.randomFill(params.getFill());

        return automaton;
    }

    public static CellularAutomaton getAutomaton() {
        return automaton;
    }
}

@@ -293,38 +293,37 @@
 r %7B%0A    private 
-static
+final
  CellularAutomat
@@ -673,108 +673,198 @@
    p
-ublic void createGame() %7B%0A        initView(%0A                automatonView,%0A                automaton
+rivate CellularAutomaton createAutomaton(CellularAutomatonFactory factory, GameParams params) %7B%0A        CellularAutomaton%3C?%3E automaton = factory.create(%0A                params.getGridSizeX()
 ,%0A  
@@ -875,32 +875,47 @@
           params
+.getGridSizeY()
 %0A        );%0A    
@@ -914,76 +914,101 @@
  );%0A
+%0A
     
-%7D%0A%0A
     
-private static void initView(AutomatonView automatonView,
+automaton.randomFill(params.getFill());%0A%0A        return automaton;%0A    %7D%0A%0A    public
  Cel
@@ -1022,25 +1022,28 @@
 tomaton 
-a
+getA
 utomaton
 , GamePa
@@ -1034,39 +1034,111 @@
 utomaton
-, GameParams params) %7B%0A
+() %7B%0A        return automaton;%0A    %7D%0A%0A    public void createGame() %7B%0A        initView(%0A        
         
@@ -1154,14 +1154,9 @@
 View
-.init(
+,
 %0A   
@@ -1235,32 +1235,38 @@
 vate static 
-Cellular
+void initView(
 Automaton cr
@@ -1262,32 +1262,30 @@
 utomaton
- createA
+View a
 utomaton
 (Cellula
@@ -1268,33 +1268,38 @@
 onView automaton
-(
+View, 
 CellularAutomato
@@ -1295,39 +1295,34 @@
 larAutomaton
-Factory factory
+ automaton
 , GameParams
@@ -1344,133 +1344,27 @@
     
-CellularAutomaton%3C?%3E automaton = factory.create(%0A                params.getGridSizeX(),%0A                params.getGridSizeY()
+automatonView.init(
 %0A   
@@ -1360,36 +1360,32 @@
 w.init(%0A        
-);%0A%0A
         automato
@@ -1389,150 +1389,42 @@
 aton
-.randomFill(params.getFill());%0A%0A        return automaton;%0A    %7D%0A%0A    public static CellularAutomaton getAutomaton() %7B%0A        return automaton
+,%0A                params%0A        )
 ;%0A  

Refactor GameManager