package gdi1sokoban.game;
import java.util.LinkedList;
import java.util.List;
/**
* GameLevelHistory class
*
* manages processed game steps
*/
class GameLevelHistory {
private int steps = 0; // completed valid steps by the player
private char[][] historyBegin; // the level when no moves are made
/**
* Adds a move with the given direction to the History
* and updates the step-counter
* @param direction
*/
void addMove(final char direction){
steps++; // increment step counter
moveHistory.add(direction); // Add direction char to history
}
/**
* deletes all steps made after the current one
*/
void deleteAfterCurrent(){
if(moveHistory.size() >= steps){
final List<Character> currHistory = moveHistory.
subList(0, steps
); // List to store all moves untill current one
moveHistory.addAll(0, currHistory); // insert moves into History
}
}
/**
* resets the counter
*/
void reset(){
steps = 0;
moveHistory.clear();
}
/**
* sets the steps counter
* @param steps value of the step counter
*/
public void setSteps(final int steps) {
this.steps = steps;
}
/**
* sets the level Map with that the history begins
* @param gameMap map of this level
*/
void setStart(final char[][] startMap){
// copy given array into historyBegin array
historyBegin = new char[startMap.length][startMap[0].length];
for(int i = 0; i<startMap.length; i++)
for(int j=0; j<startMap[0].length; j++)
historyBegin[i][j] = startMap[i][j];
}
/**
* returns the map where the history started logging
* @return game Map where everything is placed as it was when the History logger was started
*/
char[][] getStart(){
// always return copy of array because otherwise java returns a reference
final char[][] historyBeginCopy = new char[historyBegin.length][historyBegin[0].length];
for(int i = 0; i<historyBegin.length; i++)
for(int j=0; j<historyBegin[0].length; j++)
historyBeginCopy[i][j] = historyBegin[i][j];
return historyBeginCopy;
}
/**
* get number of steps made so far
* @return the number of steps made in this level ( = the position is history)
*/
int getSteps() {
return steps;
}
/**
* sets the history-entries to the given value
* @param listOfDirections LinkedList of directions
*/
moveHistory = listOfDirections;
}
/**
* get the move History as LinkedList
* @return moveHistory
*/
return moveHistory;
}
}