import static org.junit.Assert.*;

import org.junit.Test;

import inf101.v18.grid.GridDirection;
import inf101.v18.grid.ILocation;
import inf101.v18.rogue101.game.Game;
import inf101.v18.rogue101.objects.IPlayer;
import javafx.scene.input.KeyCode;

public class PlayerTest {

	@Test
	public void testOutOfBounds() {
        String NO_WALLS_MAP = "1 1\n"
                + "@\n";
        Game game = new Game(NO_WALLS_MAP);
		IPlayer player = (IPlayer) game.setCurrent(0, 0);
		ILocation loc = game.getLocation();
		player.keyPressed(game, KeyCode.LEFT);
		assertEquals(loc, game.getLocation());
	}

	/*@Test
	public void testActor() {
		String RABBIT_MAP = "5 5\n"
				+ "#####\n"
				+ "#RRR#\n"
				+ "#R@R#\n"
				+ "#RRR#\n"
				+ "#####\n";
		Game game = new Game(RABBIT_MAP);
		IPlayer player = (IPlayer) game.setCurrent(2, 2);
		ILocation loc = game.getLocation();
		player.keyPressed(game, KeyCode.LEFT);
		assertEquals(loc, game.getLocation());
		player.keyPressed(game, KeyCode.RIGHT);
		assertEquals(loc, game.getLocation());
		player.keyPressed(game, KeyCode.UP);
		assertEquals(loc, game.getLocation());
		player.keyPressed(game, KeyCode.DOWN);
		assertEquals(loc, game.getLocation());
	}*/ //TODO: Fix error "Toolkit not initialized"

	@Test
	public void testItem() {
		String CARROT_MAP = "5 5\n"
				+ "#####\n"
				+ "#CCC#\n"
				+ "#C@C#\n"
				+ "#CCC#\n"
				+ "#####\n";
		Game game = new Game(CARROT_MAP);
		IPlayer player = (IPlayer) game.setCurrent(2, 2);
		ILocation loc = game.getLocation();
		player.keyPressed(game, KeyCode.RIGHT);
		assertEquals(loc.go(GridDirection.EAST), game.getLocation());
		game.doTurn();
		player.keyPressed(game, KeyCode.LEFT);
		game.doTurn();
		player.keyPressed(game, KeyCode.LEFT);
		assertEquals(loc.go(GridDirection.WEST), game.getLocation());
	}

	@Test
	public void testWallsAndKeys() { //This probably seems a little overkill, but we need to check all keys.
		String EMPTY_MAP = "5 5\n"
				+ "#####\n"
				+ "#   #\n"
				+ "# @ #\n"
				+ "#   #\n"
				+ "#####\n";
		Game game = new Game(EMPTY_MAP);
		IPlayer player = (IPlayer) game.setCurrent(2, 2);
		ILocation loc = game.getLocation();
		player.keyPressed(game, KeyCode.UP);
		game.doTurn();
		player.keyPressed(game, KeyCode.UP);
		game.doTurn();
		assertEquals(loc.go(GridDirection.NORTH), game.getLocation());
		player.keyPressed(game, KeyCode.DOWN);
		game.doTurn();
		player.keyPressed(game, KeyCode.RIGHT);
		game.doTurn();
		assertEquals(loc.go(GridDirection.EAST), game.getLocation());
		player.keyPressed(game, KeyCode.LEFT);
		game.doTurn();
		player.keyPressed(game, KeyCode.DOWN);
		game.doTurn();
		assertEquals(loc.go(GridDirection.SOUTH), game.getLocation());
		player.keyPressed(game, KeyCode.UP);
		game.doTurn();
		player.keyPressed(game, KeyCode.LEFT);
		assertEquals(loc.go(GridDirection.WEST), game.getLocation());
	}
}
