diff options
| author | Camil Staps | 2015-04-23 18:42:02 +0200 | 
|---|---|---|
| committer | Camil Staps | 2015-04-23 18:42:02 +0200 | 
| commit | 4ccb3506c19639b410fcd5a50364c834ea153c83 (patch) | |
| tree | d04e357d970901b06c636d8a8b5cf7a5fac938e7 /app/src/main/java/com/camilstaps/rushhour/Board.java | |
| parent | OnBlock (diff) | |
Cleanup
Diffstat (limited to 'app/src/main/java/com/camilstaps/rushhour/Board.java')
| -rw-r--r-- | app/src/main/java/com/camilstaps/rushhour/Board.java | 41 | 
1 files changed, 36 insertions, 5 deletions
| diff --git a/app/src/main/java/com/camilstaps/rushhour/Board.java b/app/src/main/java/com/camilstaps/rushhour/Board.java index cfd3774..bdfb6d4 100644 --- a/app/src/main/java/com/camilstaps/rushhour/Board.java +++ b/app/src/main/java/com/camilstaps/rushhour/Board.java @@ -19,6 +19,9 @@ public class Board {      private DriveListener driveListener; +    /** +     * Move a car if possible, and call the appropriate listeners +     */      private MoveListener moveListener = new MoveListener() {          @Override          public void onMove(Car car, int offset) { @@ -38,25 +41,53 @@ public class Board {          }      }; -    public Board() { -        this(new HashSet<Car>()); -    } -      public Board(Set<Car> cars) {          for (Car car : cars) {              add(car);          }      } +    public Board() { +        this(new HashSet<Car>()); +    } +      public void add(Car car) {          car.setMoveListener(moveListener);          cars.add(car);      } +    /** +     * Add all cars to an existing layout +     * RelativeLayout is assumed, although this may work with other Layouts +     * @param context +     * @param layout +     */      public void addToLayout(Context context, ViewGroup layout) {          for (Car car : cars) { -            layout.addView(car.getImageView(context, (layout.getWidth() - layout.getPaddingLeft() - layout.getPaddingRight()) / DIMENSION)); +            layout.addView(car.getImageView( +                    context, +                    (layout.getWidth() - layout.getPaddingLeft() - layout.getPaddingRight()) / DIMENSION +            )); +        } +    } + +    /** +     * True iff the red car can move out without problems +     * @return +     */ +    public boolean isSolved() { +        for (int x = DIMENSION - 1; x >= 0; x++) { +            for (Car car : cars) { +                if (car.occupies(new Coordinate(x, 3))) { +                    if (car.canMoveHorizontally()) { +                        return true; +                    } else { +                        return false; +                    } +                } +            }          } +        return false;      }      public void setDriveListener(DriveListener dl) { | 
