aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorCamil Staps2015-04-29 12:56:33 +0200
committerCamil Staps2015-04-29 12:56:33 +0200
commit28eb6a408045971d79b379ac5ef408cf6b84ecbd (patch)
tree366de8d3fa2bff7ecdd0d947aba3178750854523 /app/src/main/java/com
parentcode license (diff)
Cleanup; victory sound
Diffstat (limited to 'app/src/main/java/com')
-rwxr-xr-xapp/src/main/java/com/camilstaps/rushhour/BoardLoader.java1
-rw-r--r--app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java19
-rwxr-xr-xapp/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java26
-rw-r--r--app/src/main/java/com/camilstaps/rushhour/MainActivity.java2
-rw-r--r--app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java34
5 files changed, 40 insertions, 42 deletions
diff --git a/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java b/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
index cb5ded7..0f9cd6f 100755
--- a/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
+++ b/app/src/main/java/com/camilstaps/rushhour/BoardLoader.java
@@ -30,6 +30,7 @@ import java.util.Scanner;
* Created by Jos on 23-4-2015.
*/
public class BoardLoader {
+
public BoardLoader()
{}
diff --git a/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java b/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java
index 053006d..e0f3c37 100644
--- a/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/FinishedActivity.java
@@ -1,21 +1,3 @@
-/*
- * Rush Hour Android app
- * Copyright (C) 2015 Randy Wanga, Jos Craaijo, Camil Staps
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
package com.camilstaps.rushhour;
import android.app.Activity;
@@ -56,6 +38,7 @@ public class FinishedActivity extends ActionBarActivity {
final int score = getIntent().getIntExtra("score", -1);
if (score != -1) {
+ TheSoundPool.getSoundPool(getBaseContext()).play(TheSoundPool.soundVictoryId, 1, 1, 1, 0, 1);
final EditText input = new EditText(this);
new AlertDialog.Builder(this)
.setTitle("Congratulations!")
diff --git a/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java b/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java
index c5740b3..8399446 100755
--- a/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/GamePlayActivity.java
@@ -31,9 +31,6 @@ import java.io.InputStream;
public class GamePlayActivity extends Activity implements Board.SolveListener {
- private SoundPool soundPool;
- private int soundBackgroundId, soundCarDriveId, soundCantMoveId;
-
Board board;
boolean isFirstTime = true;
@@ -44,7 +41,6 @@ public class GamePlayActivity extends Activity implements Board.SolveListener {
setContentView(R.layout.activity_fullscreen);
- setupSoundPool();
setupBoard();
}
@@ -76,12 +72,12 @@ public class GamePlayActivity extends Activity implements Board.SolveListener {
board.setDriveListener(new DriveListener() {
@Override
public void onDrive() {
- soundPool.play(soundCarDriveId, 1, 1, 1, 0, 1);
+ TheSoundPool.getSoundPool(getBaseContext()).play(TheSoundPool.soundCarDriveId, 1, 1, 1, 0, 1);
}
@Override
public void onBlocked() {
- soundPool.play(soundCantMoveId, 1, 1, 1, 0, 1);
+ TheSoundPool.getSoundPool(getBaseContext()).play(TheSoundPool.soundCantMoveId, 1, 1, 1, 0, 1);
}
});
@@ -98,24 +94,6 @@ public class GamePlayActivity extends Activity implements Board.SolveListener {
}
}
- /**
- * Load sounds; start background music
- */
- protected void setupSoundPool() {
- soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
- soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
- @Override
- public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
- if (sampleId == soundBackgroundId) {
- soundPool.play(soundBackgroundId, 1, 1, 2, -1, 1);
- }
- }
- });
- soundBackgroundId = soundPool.load(this, R.raw.tune, 2);
- soundCarDriveId = soundPool.load(this, R.raw.car_drive, 1);
- soundCantMoveId = soundPool.load(this, R.raw.cantmove, 1);
- }
-
@Override
public void onSolve(int score) {
Intent intent = new Intent(this, FinishedActivity.class);
diff --git a/app/src/main/java/com/camilstaps/rushhour/MainActivity.java b/app/src/main/java/com/camilstaps/rushhour/MainActivity.java
index 01b28df..e0a511f 100644
--- a/app/src/main/java/com/camilstaps/rushhour/MainActivity.java
+++ b/app/src/main/java/com/camilstaps/rushhour/MainActivity.java
@@ -30,6 +30,8 @@ public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ TheSoundPool.getSoundPool(this);
}
public void onClickHandler(View v) {
diff --git a/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java b/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java
new file mode 100644
index 0000000..c727979
--- /dev/null
+++ b/app/src/main/java/com/camilstaps/rushhour/TheSoundPool.java
@@ -0,0 +1,34 @@
+package com.camilstaps.rushhour;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.SoundPool;
+
+/**
+ * Created by camilstaps on 29-4-15.
+ */
+public class TheSoundPool {
+
+ private static SoundPool soundPool;
+ public static int soundBackgroundId, soundCarDriveId, soundCantMoveId, soundVictoryId;
+
+ public static SoundPool getSoundPool(Context context) {
+ if (soundPool == null) {
+ soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
+ soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
+ @Override
+ public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
+ if (sampleId == soundBackgroundId) {
+ soundPool.play(soundBackgroundId, 1, 1, 2, -1, 1);
+ }
+ }
+ });
+ soundBackgroundId = soundPool.load(context, R.raw.tune, 2);
+ soundCarDriveId = soundPool.load(context, R.raw.car_drive, 1);
+ soundCantMoveId = soundPool.load(context, R.raw.cantmove, 1);
+ soundVictoryId = soundPool.load(context, R.raw.victory, 1);
+ }
+ return soundPool;
+ }
+
+}