package com.kduda.battleships.controllers;

import com.kduda.battleships.models.board.Board;
import com.kduda.battleships.models.board.Cell;
import com.kduda.battleships.models.units.Unit;
import com.kduda.battleships.models.units.UnitFactory;
import com.kduda.battleships.models.units.UnitType;
import javafx.fxml.Initializable;
import javafx.geometry.Orientation;
import javafx.scene.layout.VBox;

import java.net.URL;
import java.util.ResourceBundle;

public class BattleshipsController implements Initializable {
    public VBox enemyBoardArea;
    public VBox playerBoardArea;
    Board enemyBoard;
    Board playerBoard;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        initializeBoards();
    }

    private void initializeBoards() {
        enemyBoard = new Board(true, event -> {
            //TODO: click handler
            if (!BattleshipsConfig.INSTANCE.isGameRunning)
                return;
        }, event -> {
            //TODO: hover handler
            return;
        });
        enemyBoardArea.getChildren().add(enemyBoard);

        playerBoard = new Board(false, event -> {
            //TODO: click handler: rozstawianie, koniec statkow -> rozpocznij gre
            if (BattleshipsConfig.INSTANCE.isGameRunning)
                return;

            //TODO: stawianie statkow
            Cell cell = (Cell) event.getSource();
            Unit unit = UnitFactory.INSTANCE.createGroundLevelUnit(UnitType.Ship, 3, Orientation.VERTICAL);
            playerBoard.placeUnit(unit, cell);

        }, event -> {
            //TODO: hover handler
            if (BattleshipsConfig.INSTANCE.isGameRunning)
                return;
            Cell cell = (Cell) event.getSource();
        });
        playerBoardArea.getChildren().addAll(playerBoard);


        //HANDLERS

//        playerBoard = new Board(false, event -> {
//            if (running)
//                return;
//
//            Cell cell = (Cell) event.getSource();
//            if (playerBoard.placeShip(new Ship(shipsToPlace, event.getButton() == MouseButton.PRIMARY), cell.x, cell.y)) {
//                if (--shipsToPlace == 0) {
//                    startGame();
//                }
//            }
//        });

//        enemyBoard = new Board(true, event -> {
//            if (!running)
//                return;
//
//            Cell cell = (Cell) event.getSource();
//            if (cell.wasShot)
//                return;
//
//            enemyTurn = !cell.shootCell();
//
//            if (enemyBoard.ships == 0) {
//                System.out.println("YOU WIN");
//                System.exit(0);
//            }
//
//            if (enemyTurn)
//                enemyMove();
//        });


    }
}

@@ -248,121 +248,33 @@
 ort 
-com.kduda.battleships.models.units.UnitType;%0Aimport javafx.fxml.Initializable;%0Aimport javafx.geometry.Orientation
+javafx.fxml.Initializable
 ;%0Aim
@@ -1051,90 +1051,8 @@
 %3E %7B%0A
-            //TODO: click handler: rozstawianie, koniec statkow -%3E rozpocznij gre%0A
     
@@ -1150,16 +1150,19 @@
 //TODO: 
+roz
 stawiani
@@ -1187,42 +1187,52 @@
     
-Cell cell = (Cell) event.getSource
+Unit unit = UnitFactory.INSTANCE.getNextUnit
 ();%0A
@@ -1247,101 +1247,153 @@
     
-Unit 
+if (
 unit =
- UnitFactory.INSTANCE.createGroundLevelUnit(UnitType.Ship, 3, Orientation.VERTICAL
+= null) %7B%0A                //TODO: start game%0A                startGame();%0A            %7D%0A            Cell cell = (Cell) event.getSource(
 );%0A 
@@ -2136,16 +2136,18 @@
    %7D);%0A%0A
+%0A%0A
 //      
@@ -2632,11 +2632,150 @@
 %0A%0A%0A    %7D
+%0A%0A    private void startGame() %7B%0A        System.out.println(%22game started%22);%0A        BattleshipsConfig.INSTANCE.isGameRunning = true;%0A    %7D
 %0A%7D%0A

Add getting ships from factory and starting the game