Package testapp1610

Source Code of testapp1610.GameObject

package testapp1610;

import basicObjects.DctrPtrnPieces.Piece;
import basicObjects.Factories.PieceFactory;
import basicObjects.Factories.PlayerFactory;
import basicObjects.Factories.singletonBoardFactory;
import basicObjects.Players.AbstractPlayer;
import basicObjects.boardObjects.Board;
import java.util.ArrayList;

public class GameObject { //this is the main object that holds all the current game objects and destroys them with itself

    PlayerFactory playerFactory;
    ArrayList<Piece> currentPieces = new ArrayList();
    Board currentBoard = new Board();
    AbstractPlayer[] players;
    GameState currentGame;
    AbstractPlayer currentPlayer;

    public GameObject(String p1, String p2, String boardType) {

        currentPieces = PieceFactory.getInstanceOfPieces();
        playerFactory = new PlayerFactory();
        players = playerFactory.createPlayers(p1, p2); //TODO default for the moment should be adjusted for user input
        currentBoard = singletonBoardFactory.getInstanceOfBoard(boardType);
        currentGame = new GameState();
        currentBoard.register(currentGame);
        currentGame.setSubject(currentBoard);

    }

    public void setCurrentPlayer(AbstractPlayer currentPlayer) {
        this.currentPlayer = currentPlayer;
    }

    public AbstractPlayer checkGameState() {
        boolean state;
        state = currentGame.update();
        boolean squaresFilled = true;

        if (state == true) {
            return currentPlayer;
        } else if (state == false) {
            //check have all the pieces been played and if they have call it a draw
            //otherwise play on
            for (int x = 0; x < currentBoard.getSquares().size(); x++) {
                if (currentBoard.getSquares().get(x).isFilled()) {
                    //Do nothing
                } else {
                    squaresFilled = false;
                }
            }
            if (squaresFilled == false) {
                //continue game
                return null; //if null is returned there is no winner yet
            } else if (squaresFilled == true) {
                //declare the game a draw
                return null; //sort this out there should be a way of declaring a draw!
            }
        }
        return null;
    }
}
TOP

Related Classes of testapp1610.GameObject

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.