package gdi.ws0809.test;
import gdi1sokoban.exceptions.InternalFailureException;
import gdi1sokoban.exceptions.ParameterOutOfRangeException;
import gdi1sokoban.exceptions.ParseException;
import gdi1sokoban.main.Sokoban;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
/*============================================================================*/
/**
* Provide an implementation for SokobanTest in this class. Your game must
* compile and run without this class. This class is just meant to adapt the
* test cases to your implementation.
*
* @author daniel
*
*/
public class SokobanTestAdapter implements SokobanTest {
private String playerName =
"";
public static void init() {
Sokoban.startEngine(null);
try {
Sokoban.getEngine().newGame();
e.printStackTrace();
} catch (final ParameterOutOfRangeException e) {
e.printStackTrace();
} catch (final InternalFailureException e) {
e.printStackTrace();
e.printStackTrace();
e.printStackTrace();
}
}
public String currentLevelToString
()
{
return Sokoban.getEngine().getGameLevel().toString();
}
{
Sokoban.getEngine().newGame(lvl);
}
public boolean isSolved()
{
return Sokoban.getEngine().getGameLevel().isSolved();
}
public void moveWorker(final char direction)
{
try {
Sokoban.getEngine().roundEnd(Sokoban.getEngine().movePlayer(direction), playerName);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
}
}
public void setLevelDir
(final File levelDir
)
{
try {
Sokoban.getEngine().setLevelDir(levelDir, 10);
} catch (final InternalFailureException e) {
e.printStackTrace();
}
}
public void startNextLevel
() throws Exception
{
Sokoban.getEngine().newGame(Sokoban.getEngine().getCurrentLevelNr()+1);
}
public int getStepsInCurrentLevel()
{
return Sokoban.getEngine().getGameLevel().getSteps();
}
public void writeHighScoreFile()
{
try {
Sokoban.getEngine().getHighscores().saveHighscores();
} catch (final InternalFailureException e) {
e.printStackTrace();
}
}
public void setPlayerName
(final String name
)
{
playerName = name;
}
public void redoLastUndoneMove
() throws Exception
{
Sokoban.getEngine().redo();
}
{
Sokoban.getEngine().undo();
}
public void loadGame
(final File saveFile
)
{
Sokoban.getEngine().loadGame(saveFile);
}
public void saveGame
(final File f
)
{
Sokoban.getEngine().saveGame(f);
}
public boolean isDeadlock()
{
try {
return Sokoban.getEngine().getGameLevel().hasDeadlock();
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return false;
}
}
public boolean canMoveCrate(final int i, final int j, final char c)
{
int destTop = j, destLeft = i;
switch(c){
case 'R':
destLeft++;
case 'L':
destLeft--;
case 'U':
destTop--;
case 'D':
destTop++;
}
try {
return Sokoban.getEngine().getGameLevel().setPosition(j, i, destTop, destLeft);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
}
return false;
}
public boolean createHighscoreEntry
(final String playername,
final int i,
final int j,
final int k
)
{
if (Sokoban.getEngine().getHighscores().isHighscore(i, j, k)) {
Sokoban.
getEngine().
getHighscores().
addHighscore(i, playername,
String.
valueOf(j
),
String.
valueOf(k
));
return true;
} else
return false;
}
public String getBestPlayerName
()
{
final String highscoreData = Sokoban.
getEngine().
getHighscores().
toString();
final String[] hsRows = highscoreData.
split("\n");
final String[] hsFirstRow = hsRows
[0].
split("\t");
return hsFirstRow[1];
}
public int getCrateCount()
{
return Sokoban.getEngine().getGameLevel().countCrates();
}
public int getGoalCount()
{
return Sokoban.getEngine().getGameLevel().countGoals();
}
public int getHighscoreCount()
{
return Sokoban.getEngine().getHighscores().getAllHighscoresCount();
}
public int getLevelHeight()
{
return Sokoban.getEngine().getGameLevel().getHeight();
}
public int getLevelWidth()
{
return Sokoban.getEngine().getGameLevel().getWidth();
}
public int getWallCount()
{
return Sokoban.getEngine().getGameLevel().countWalls();
}
public int getWorkerPositionX()
{
try {
return Sokoban.getEngine().getGameLevel().getPlayerPos().left;
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return -1;
}
}
public int getWorkerPositionY()
{
try {
return Sokoban.getEngine().getGameLevel().getPlayerPos().top;
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return -1;
}
}
public boolean isCrateAt(final int i, final int j)
{
try {
return Sokoban.getEngine().getGameLevel().isCrate(j, i);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return false;
}
}
public boolean isGoalAt(final int i, final int j)
{
try {
return Sokoban.getEngine().getGameLevel().isGoal(j, i);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return false;
}
}
public boolean isWallAt(final int i, final int j)
{
try {
return Sokoban.getEngine().getGameLevel().isWall(j, i);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return false;
}
}
public void clearHighscoreList()
{
Sokoban.getEngine().getHighscores().resetHighscores();
}
public void moveWorkerSequence
(final String moves
)
{
for(final char m : moves.toCharArray())
try {
Sokoban.getEngine().movePlayer(m);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
}
}
public boolean checkWallBounding() {
try {
return Sokoban.getEngine().getGameLevel().checkWallBounding();
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return false;
}
}
public String solveLevel
(final int maxTime
) {
try {
return Sokoban.getEngine().solve(maxTime);
} catch (final ParameterOutOfRangeException e) {
System.
err.
println("Fehler: Ungültige Levelkoordinaten!");
return "";
}
}
}