package jrummikub.model;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

/** Class managing the overall and momentary GameState */
public class GameState implements IGameState {
	private ITable table;
	private List<Player> players;
	private int activePlayer;
	private StoneHeap gameHeap;

	/** 
	 * Create a new GameState with an empty table and (currntly) 4 new players.
	 */
	public GameState() {
		table = new Table();
		players = new ArrayList<Player>();
		players.add(new Player("Ida", Color.RED));
		players.add(new Player("Matthias", Color.YELLOW));
		players.add(new Player("Jannis", Color.GREEN));
		players.add(new Player("Bennet", Color.BLACK));
		activePlayer = 0;
		gameHeap = new StoneHeap();
	}

	@Override
	public ITable getTable() {
		return table;
	}

	@Override
	public void setTable(ITable table) {
		this.table = table;
	}

	@Override
	public int getPlayerCount() {
		return players.size();
	}

	@Override
	public void nextPlayer() {
		activePlayer = (activePlayer + 1) % players.size();
	}

	@Override
	public IPlayer getNthNextPlayer(int i) {
		return players.get((activePlayer + i) % players.size());
	}

	@Override
	public IPlayer getActivePlayer() {
		return players.get(activePlayer);
	}

	@Override
	public StoneHeap getGameHeap() {
		return gameHeap;
	}
}
