From 7e966c69d159ea76608115766d31551edc64bd06 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Wed, 22 Apr 2015 12:53:10 +0200
Subject: Cleanup
---
.idea/workspace.xml | 189 +++++++++------------
.../main/java/com/camilstaps/rushhour/Board.java | 9 +-
app/src/main/java/com/camilstaps/rushhour/Car.java | 11 --
.../camilstaps/rushhour/FullscreenActivity.java | 26 +--
4 files changed, 92 insertions(+), 143 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 11a6c42..d00696e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -42,59 +42,20 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1356,9 +1317,9 @@
-
-
+
+
@@ -1729,12 +1690,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -1744,8 +1705,8 @@
-
-
+
+
@@ -1771,12 +1732,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -1786,8 +1747,8 @@
-
-
+
+
@@ -1813,12 +1774,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -1828,8 +1789,8 @@
-
-
+
+
@@ -1855,12 +1816,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -1877,8 +1838,8 @@
-
-
+
+
@@ -1904,12 +1865,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -1926,8 +1887,8 @@
-
-
+
+
@@ -2031,17 +1992,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -2050,28 +2000,43 @@
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/app/src/main/java/com/camilstaps/rushhour/Board.java b/app/src/main/java/com/camilstaps/rushhour/Board.java
index e99c438..eeb2580 100644
--- a/app/src/main/java/com/camilstaps/rushhour/Board.java
+++ b/app/src/main/java/com/camilstaps/rushhour/Board.java
@@ -24,12 +24,9 @@ public class Board {
public void onMove(Car car, int offset) {
Coordinate newC = car.wouldMoveTo(offset);
if (newC.getY() > DIMENSION - 1 || newC.getX() > DIMENSION - 1 || newC.getX() < 0 || newC.getY() < 0) return;
- for (Car iter : cars) {
- if (iter.occupies(newC)) {
- Log.d("Board", "Can't move");
+ for (Car iter : cars)
+ if (iter.occupies(newC))
return;
- }
- }
car.move(offset);
driveListener.onDrive();
}
@@ -51,8 +48,6 @@ public class Board {
}
public void addToLayout(Context context, ViewGroup layout) {
- Log.d("Board", Integer.toString(layout.getWidth()));
-
for (Car car : cars) {
layout.addView(car.getImageView(context, (layout.getWidth() - layout.getPaddingLeft() - layout.getPaddingRight()) / DIMENSION));
}
diff --git a/app/src/main/java/com/camilstaps/rushhour/Car.java b/app/src/main/java/com/camilstaps/rushhour/Car.java
index aa654f8..2dce203 100644
--- a/app/src/main/java/com/camilstaps/rushhour/Car.java
+++ b/app/src/main/java/com/camilstaps/rushhour/Car.java
@@ -16,7 +16,6 @@ import android.widget.TableLayout;
*/
public class Car {
- //private int startCoordinate.getX(), startCoordinate.getY(), endCoordinate.getX(), endCoordinate.getY();
private Coordinate startCoordinate, endCoordinate;
private final int colour;
@@ -42,20 +41,10 @@ public class Car {
this.colour = colour;
}
- public int getColour() { return colour; }
-
public void setMoveListener(MoveListener listener) {
moveListener = listener;
}
- private int getWidth() {
- return (SIZE + MARGIN) * (endCoordinate.getX() - startCoordinate.getX()) + SIZE;
- }
-
- private int getHeight() {
- return (SIZE + MARGIN) * (endCoordinate.getY() - startCoordinate.getY()) + SIZE;
- }
-
public void setLayoutParams() {
ViewGroup.MarginLayoutParams marginParams = new RelativeLayout.LayoutParams(calculatedWidth, calculatedHeight);
marginParams.setMargins((int) (startCoordinate.getX() * (widthPerCell + MARGIN) + MARGIN), (int) (startCoordinate.getY() * (widthPerCell + MARGIN) + MARGIN), MARGIN, MARGIN);
diff --git a/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java b/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java
index 620f2b2..495c996 100644
--- a/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/FullscreenActivity.java
@@ -31,9 +31,6 @@ public class FullscreenActivity extends Activity {
setContentView(R.layout.activity_fullscreen);
- final RelativeLayout boardLayout = (RelativeLayout) findViewById(R.id.board);
- Log.d("FA", boardLayout.toString());
-
final Board board = new Board();
board.add(new Car(new Coordinate(0,0), new Coordinate(2,0), Color.YELLOW));
board.add(new Car(new Coordinate(3,0), new Coordinate(3,1), Color.rgb(128,223,182)));
@@ -48,15 +45,6 @@ public class FullscreenActivity extends Activity {
board.add(new Car(new Coordinate(5,4), new Coordinate(5,5), Color.rgb(219,202,161)));
board.add(new Car(new Coordinate(0,5), new Coordinate(2,5), Color.rgb(25,195,167)));
- ViewTreeObserver vto = boardLayout.getViewTreeObserver();
- vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- boardLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
- board.addToLayout(getBaseContext(), boardLayout);
- }
- });
-
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
@@ -66,10 +54,22 @@ public class FullscreenActivity extends Activity {
});
soundBackgroundId = soundPool.load(this, R.raw.car_drive, 1);
+ final RelativeLayout boardLayout = (RelativeLayout) findViewById(R.id.board);
+ ViewTreeObserver vto = boardLayout.getViewTreeObserver();
+ vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ boardLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ board.addToLayout(getBaseContext(), boardLayout);
+ }
+ });
+
board.setDriveListener(new DriveListener() {
@Override
public void onDrive() {
- soundPool.play(soundBackgroundId, 1, 1, 1, 0, 1f);
+ if (soundBackgroundLoaded) {
+ soundPool.play(soundBackgroundId, 1, 1, 1, 0, 1f);
+ }
}
});
}
--
cgit v1.2.3