diff options
author | Camil Staps | 2015-04-29 11:43:50 +0200 |
---|---|---|
committer | Camil Staps | 2015-04-29 11:43:50 +0200 |
commit | 71f415e5c1cac0ed491113e35a65ebc1ae75bb7d (patch) | |
tree | 9baddadf846681823228340b4346d817f813f4bf /app/src/main/java/com/camilstaps/rushhour/Board.java | |
parent | Merge branch 'master' into MainActivity (diff) |
Highscores
Diffstat (limited to 'app/src/main/java/com/camilstaps/rushhour/Board.java')
-rw-r--r-- | app/src/main/java/com/camilstaps/rushhour/Board.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/app/src/main/java/com/camilstaps/rushhour/Board.java b/app/src/main/java/com/camilstaps/rushhour/Board.java index bdfb6d4..7f1f842 100644 --- a/app/src/main/java/com/camilstaps/rushhour/Board.java +++ b/app/src/main/java/com/camilstaps/rushhour/Board.java @@ -1,9 +1,11 @@ package com.camilstaps.rushhour; import android.content.Context; +import android.content.Intent; import android.util.Log; import android.view.ViewGroup; import android.widget.RelativeLayout; +import android.widget.Toast; import java.util.HashSet; import java.util.Set; @@ -18,6 +20,9 @@ public class Board { public static final int DIMENSION = 6; private DriveListener driveListener; + private SolveListener solveListener; + + private int score; /** * Move a car if possible, and call the appropriate listeners @@ -37,6 +42,10 @@ public class Board { } } car.move(offset); + score++; + if (isSolved() && solveListener != null) { + solveListener.onSolve(score); + } driveListener.onDrive(); } }; @@ -76,9 +85,9 @@ public class Board { * @return */ public boolean isSolved() { - for (int x = DIMENSION - 1; x >= 0; x++) { + for (int x = DIMENSION - 1; x >= 0; x--) { for (Car car : cars) { - if (car.occupies(new Coordinate(x, 3))) { + if (car.occupies(new Coordinate(x, 2))) { if (car.canMoveHorizontally()) { return true; } else { @@ -94,4 +103,12 @@ public class Board { driveListener = dl; } + public interface SolveListener { + public void onSolve(int score); + } + + public void setSolveListener(SolveListener sl) { + solveListener = sl; + } + } |