package de.sopa.model;

import de.sopa.GameFieldDestroyer;
import de.sopa.observer.Observer;
import java.util.ArrayList;
import java.util.List;

/**
 * David Schilling - davejs92@gmail.com
 */
public class GameServiceImpl implements GameService {

    private final GameFieldService gameFieldService;
    private final FieldCreator fieldCreator;
    private GameField gameField;
    private List<Observer> observers;
    private boolean solvedPuzzle;

    public GameServiceImpl() {
        observers = new ArrayList<>();
        gameFieldService = new GameFieldService();
        fieldCreator = new FieldCreator();
        solvedPuzzle = false;
    }

    @Override
    public boolean solvedPuzzle() {
        return solvedPuzzle;
    }

    @Override
    public void shiftLine(boolean horizontal, int row, int steps) {
        gameFieldService.shiftLine(gameField, horizontal, row, steps);
        solvedPuzzle = gameFieldService.solvedPuzzle(gameField);
        notifyAllObserver();
    }

    @Override
    public GameField getGameField() {
        return gameField;
    }

    @Override
    public void startGame() {
        gameField = fieldCreator.generateSolvedField(6, 6);
        new GameFieldDestroyer().destroyField(gameField, 3, 5, 3);
        solvedPuzzle = gameFieldService.solvedPuzzle(gameField);
    }

    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyAllObserver() {
        for (Observer observer : observers) {
            observer.update();
        }
    }
}

@@ -21,43 +21,8 @@
 l;%0A%0A
-import de.sopa.GameFieldDestroyer;%0A
 impo
@@ -51,16 +51,16 @@
 server;%0A
+
 import j
@@ -282,22 +282,22 @@
 al Field
-Creato
+Handle
 r fieldC
@@ -563,22 +563,22 @@
 ew Field
-Creato
+Handle
 r();%0A   

fix imports