package jrummikub.model;

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

/**
 * Mock class for {@link RoundState}
 */
@SuppressWarnings("serial")
public class MockRoundState implements IRoundState {
	/** */
	public MockTable table;
	/** */
	public ITable setTable;
	/** */
	public List<MockPlayer> players;
	/** */
	public int activePlayer;
	/** */
	public StoneHeap gameHeap;
	/** */
	public GameSettings gameSettings;
	/** */
	public IPlayer lastPlayer;
	/** */
	public int turnNumber;
	/** */
	public GameState gameState;

	/** */
	public MockRoundState() {
		table = new MockTable();
		players = new ArrayList<MockPlayer>();
		players.add(new MockPlayer(new PlayerSettings("Player 1", Color.RED),
				gameSettings));
		players.add(new MockPlayer(new PlayerSettings("Player 2", Color.YELLOW),
				gameSettings));
		players.add(new MockPlayer(new PlayerSettings("Player 3", Color.GREEN),
				gameSettings));
		players.add(new MockPlayer(new PlayerSettings("Player 4", Color.BLACK),
				gameSettings));
		activePlayer = 0;
		gameSettings = new GameSettings();
		gameHeap = new StoneHeap(gameSettings);
		gameSettings.setInitialMeldThreshold(30);
		turnNumber = -3;
	}

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

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

	/** Changes the activePlayer to the next {@link Player} in the list */
	@Override
	public void nextPlayer() {
		activePlayer = (activePlayer + 1) % players.size();
	}

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

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

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

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

	@Override
	public GameSettings getGameSettings() {
		return gameSettings;
	}

	@Override
	public IPlayer getLastPlayer() {
		return lastPlayer;
	}

	@Override
	public void setLastPlayer(IPlayer lastPlayer) {
		this.lastPlayer = lastPlayer;
	}

	@Override
	public void setActivePlayerNumber(int i) {
		int j = i % players.size();
		if (j < 0) {
			j += players.size();
		}
		activePlayer = j;
	}

	@Override
	public IPlayer getNthPlayer(int i) {
		int j = i % players.size();
		if (j < 0) {
			j += players.size();
		}
		return players.get(j);
	}

	public int getTurnNumber() {
		return turnNumber;
	}

	@Override
	public void nextTurn() {
		turnNumber++;
	}

	@Override
	public GameState getGameState() {
		return gameState;
	}
}
