diff --git a/src/levels.csv b/src/levels.csv index 00bdce2..cbd1ca0 100644 --- a/src/levels.csv +++ b/src/levels.csv @@ -1,20 +1,20 @@ -1,1,13,14,0,1,5,17,6,18,9,21,24,30,28,29,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -2,1,12,13,0,6,3,5,9,15,11,23,16,22,18,20,26,32,28,29,30,31,33,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -3,1,13,14,15,27,19,20,23,35,25,31,32,33,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -4,1,13,14,0,12,3,15,20,26,21,23,29,35,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -5,1,13,14,0,1,3,15,5,11,6,18,10,22,17,23,19,21,24,30,28,29,34,35,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -11,2,13,14,0,12,1,2,3,15,20,26,21,23,29,35,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -12,2,12,13,0,6,1,2,5,17,8,20,21,23,30,32,28,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -13,2,15,16,0,1,2,3,4,10,8,14,11,23,13,19,18,30,21,22,27,33,28,29,31,32,34,35,-1,-1,-1,-1,-1,-1 -14,2,14,15,0,1,2,8,10,11,12,18,13,19,16,22,17,23,20,21,26,32,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1 -15,2,14,15,1,2,3,4,6,7,8,9,10,22,11,23,12,24,13,25,20,26,21,27,28,29,31,32,33,34,-1,-1,-1,-1 -21,3,13,14,0,1,2,8,3,15,6,18,19,21,33,35,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -22,3,13,14,2,8,3,5,6,12,9,21,10,11,19,25,22,23,24,30,26,27,29,35,31,33,-1,-1,-1,-1,-1,-1,-1,-1 -23,3,15,16,2,4,5,17,8,14,9,10,20,26,21,27,22,23,28,29,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -24,3,14,15,2,8,3,4,7,13,12,18,16,22,19,20,24,26,28,34,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -25,3,13,14,0,1,2,8,4,5,6,7,11,23,12,24,16,22,19,21,25,31,27,33,28,29,34,35,-1,-1,-1,-1,-1,-1 -31,4,13,14,0,1,3,5,9,15,10,11,12,18,17,29,20,32,21,22,24,25,33,35,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -32,4,12,13,0,1,2,14,3,9,4,5,18,24,19,20,21,22,23,35,27,33,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -33,4,12,13,1,7,2,14,4,5,18,24,19,20,21,22,23,35,25,26,27,33,28,34,30,32,-1,-1,-1,-1,-1,-1,-1,-1 -34,4,12,13,0,6,3,5,9,15,11,23,16,22,18,20,21,27,26,32,28,29,30,31,33,34,-1,-1,-1,-1,-1,-1,-1,-1 -35,4,12,13,2,14,3,4,5,17,9,15,18,24,19,21,25,26,27,33,28,34,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +1,1,8,13,14,0,1,5,17,6,18,9,21,24,30,28,29,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +2,1,8,12,13,0,6,3,5,9,15,11,23,16,22,18,20,26,32,28,29,30,31,33,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +3,1,14,13,14,15,27,19,20,23,35,25,31,32,33,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +4,1,9,13,14,0,12,3,15,20,26,21,23,29,35,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +5,1,9,13,14,0,1,3,15,5,11,6,18,10,22,17,23,19,21,24,30,28,29,34,35,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +11,2,15,13,14,0,12,1,2,3,15,20,26,21,23,29,35,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +12,2,17,12,13,0,6,1,2,5,17,8,20,21,23,30,32,28,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +13,2,21,15,16,0,1,2,3,4,10,8,14,11,23,13,19,18,30,21,22,27,33,28,29,31,32,34,35,-1,-1,-1,-1,-1,-1 +14,2,17,14,15,0,1,2,8,10,11,12,18,13,19,16,22,17,23,20,21,26,32,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1 +15,2,23,14,15,1,2,3,4,6,7,8,9,10,22,11,23,12,24,13,25,20,26,21,27,28,29,31,32,33,34,-1,-1,-1,-1 +21,3,21,13,14,0,1,2,8,3,15,6,18,19,21,33,35,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +22,3,26,13,14,2,8,3,5,6,12,9,21,10,11,19,25,22,23,24,30,26,27,29,35,31,33,-1,-1,-1,-1,-1,-1,-1,-1 +23,3,29,15,16,2,4,5,17,8,14,9,10,20,26,21,27,22,23,28,29,32,34,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +24,3,25,14,15,2,8,3,4,7,13,12,18,16,22,19,20,24,26,28,34,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +25,3,27,13,14,0,1,2,8,4,5,6,7,11,23,12,24,16,22,19,21,25,31,27,33,28,29,34,35,-1,-1,-1,-1,-1,-1 +31,4,37,13,14,0,1,3,5,9,15,10,11,12,18,17,29,20,32,21,22,24,25,33,35,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +32,4,37,12,13,0,1,2,14,3,9,4,5,18,24,19,20,21,22,23,35,27,33,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +33,4,30,12,13,1,7,2,14,4,5,18,24,19,20,21,22,23,35,25,26,27,33,28,34,30,32,-1,-1,-1,-1,-1,-1,-1,-1 +34,4,43,12,13,0,6,3,5,9,15,11,23,16,22,18,20,21,27,26,32,28,29,30,31,33,34,-1,-1,-1,-1,-1,-1,-1,-1 +35,4,43,12,13,2,14,3,4,5,17,9,15,18,24,19,21,25,26,27,33,28,34,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 diff --git a/src/rushhour/Converter.java b/src/rushhour/Converter.java index 9e9cb15..e5ab81e 100644 --- a/src/rushhour/Converter.java +++ b/src/rushhour/Converter.java @@ -31,17 +31,19 @@ public void reload() throws NumberFormatException, IOException{ String[] columns = line.split(","); int Nr = Integer.parseInt(columns[0]); int Level = Integer.parseInt(columns[1]); - Car startcar = getCarFromCoords(Integer.parseInt(columns[2]), Integer.parseInt(columns[3]), true); + int MaxMoves = Integer.parseInt(columns[2]); + + Car startcar = getCarFromCoords(Integer.parseInt(columns[3]), Integer.parseInt(columns[4]), true); cars.add(startcar); - for(int i = 4; i < 34; i+=2){ + for(int i = 5; i < 35; i+=2){ int pos1 = Integer.parseInt(columns[i]); int pos2 = Integer.parseInt(columns[i+1]); if(pos1 == -1) break; cars.add(getCarFromCoords(pos1, pos2, false)); } - thm = new Map(Nr, cars); + thm = new Map(Nr, cars, MaxMoves); Level thl = getLevel(Level); thl.addMap(thm); } @@ -60,7 +62,7 @@ private Level getLevel(int Level){ private Car getCarFromCoords(int pos1, int pos2, boolean isStartCar){ Point startPos = new Point((int)pos1%6, (int)pos1/6); Point endPos = new Point((int)pos2%6, (int)pos2/6); - boolean Rotation = startPos.getX() ==endPos.getX(); + boolean Rotation = startPos.getX() == endPos.getX(); int Lenght = 0; if(Rotation) Lenght = (int) (endPos.getY() - startPos.getY()); else Lenght = (int) (endPos.getX() - startPos.getX()); diff --git a/src/rushhour/Map.java b/src/rushhour/Map.java index d88a09c..f52edf6 100644 --- a/src/rushhour/Map.java +++ b/src/rushhour/Map.java @@ -5,10 +5,12 @@ public class Map { private ArrayList cars = null; private int Nr = 0; + private int MaxMoves = 0; - public Map(int Nr, ArrayList cars){ + public Map(int Nr, ArrayList cars, int MaxMoves){ this.cars = cars; this.Nr = Nr; + this.MaxMoves = MaxMoves; } public ArrayList getCars() { @@ -27,4 +29,8 @@ public String toString(){ public void reset() { for(Car c : cars) c.reset(); } + + public int getMaxMoves(){ + return MaxMoves; + } } diff --git a/src/rushhour/Rushhour.java b/src/rushhour/Rushhour.java index 3fbb1d3..b14dd27 100644 --- a/src/rushhour/Rushhour.java +++ b/src/rushhour/Rushhour.java @@ -33,4 +33,7 @@ public boolean isPuzzleSolved(){ public void setMap(Map map){ thisMap = map; } + public int getMaxMoves(){ + return thisMap.getMaxMoves(); + } } diff --git a/src/rushhour/Window.java b/src/rushhour/Window.java index 6c5f543..ab44f6f 100644 --- a/src/rushhour/Window.java +++ b/src/rushhour/Window.java @@ -99,7 +99,7 @@ public void mouseReleased(MouseEvent e) { carGotSelected = false; if(!oldpos.equals(selectedCar.getCoords(0))) selectedCar.moveMade(); // only if car got moved selectedCar.setSelected(false); - Window.setTitle("Rush Hour, Moves made: " + rh.getAllMoves()); + Window.setTitle("Rush Hour, Moves made: " + rh.getAllMoves()+", Max Moves: " +rh.getMaxMoves()); drawField(); Window.setCursor(Cursor.DEFAULT_CURSOR); if(rh.isPuzzleSolved()){