Skip to content

Commit

Permalink
Fixed issue whereby a game that was being created from a Bundle was o…
Browse files Browse the repository at this point in the history
…verriding the game mode selected (Puzzle or Player vs CPU).
  • Loading branch information
forteri76 committed Aug 14, 2013
1 parent f7cb953 commit b4bc4bd
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 64 deletions.
7 changes: 3 additions & 4 deletions src/com/efortin/frozenbubble/SplashScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void addHomeButtons() {
start2pGameButton.setOnClickListener(new Button.OnClickListener(){

public void onClick(View v){
// Process the button tap and start a 2 player game.
// Process the button tap and start/resume a 2 player game.
startFrozenBubble(2);
}
});
Expand Down Expand Up @@ -215,7 +215,7 @@ public void onCreate(Bundle savedInstanceState) {
LayoutParams.FILL_PARENT));
myImageView = new ImageView(this);

if (FrozenBubble.isRunning)
if (FrozenBubble.numPlayers != 0)
startFrozenBubble(FrozenBubble.numPlayers);
else if (getIntent().hasExtra("startHomeScreen")) {
setBackgroundImage(R.drawable.home_screen);
Expand Down Expand Up @@ -354,8 +354,7 @@ private void startFrozenBubble(int numPlayers) {
//
//
Intent intent = new Intent(this, FrozenBubble.class);
if (numPlayers > 1)
intent.putExtra("numPlayers", (int)numPlayers);
intent.putExtra("numPlayers", (int)numPlayers);
startActivity(intent);
//
// Terminate the splash screen activity.
Expand Down
140 changes: 80 additions & 60 deletions src/org/jfedor/frozenbubble/FrozenBubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public class FrozenBubble extends Activity
public final static int POINT_TO_SHOOT = 1;
public final static int ROTATE_TO_SHOOT = 2;

public static boolean isRunning = false;
public static int numPlayers = 0;
public static int numPlayers = 0;

private static boolean adsOn = true;
private static int collision = BubbleSprite.MIN_PIX;
Expand Down Expand Up @@ -219,7 +218,6 @@ public void onCreate(Bundle savedInstanceState) {
// Log.i(TAG, "FrozenBubble.onCreate(null)");
//}
super.onCreate(savedInstanceState);
isRunning = true;
setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
restoreGamePrefs();
Expand All @@ -237,46 +235,14 @@ public void onOrientationChanged(int arg0) {

// Allow editor functionalities.
Intent intent = getIntent();
if ((null == intent) ||
(null == intent.getExtras()) ||
!intent.getExtras().containsKey("levels")) {
// Default levels.
activityCustomStarted = false;
// Check if this is a single player or multiplayer game.
numPlayers = 1;
if (intent.hasExtra("numPlayers"))
numPlayers = intent.getIntExtra("numPlayers", 1);
if (numPlayers > 1) {
mMultiplayerGameView = new MultiplayerGameView(this, numPlayers);
setContentView(mMultiplayerGameView);
mMultiplayerGameView.setGameListener(this);
mMultiplayerGameThread = mMultiplayerGameView.getThread();
if (savedInstanceState != null) {
int savedPlayers = savedInstanceState.getInt("numPlayers");
if (savedPlayers == 2)
mMultiplayerGameThread.restoreState(savedInstanceState);
}
mMultiplayerGameThread.startOpponent();
mMultiplayerGameView.requestFocus();
}
else {
setContentView(R.layout.activity_frozen_bubble);
mGameView = (GameView)findViewById(R.id.game);
mGameView.setGameListener(this);
mGameThread = mGameView.getThread();
if (savedInstanceState != null) {
int savedPlayers = savedInstanceState.getInt("numPlayers");
if (savedPlayers == 1)
mGameThread.restoreState(savedInstanceState);
}

mGameView.requestFocus();
}
setFullscreen();
playMusic(false);
}
else {
startCustomGame(intent);
try {
if ((null == intent) || (null == intent.getExtras()) ||
!intent.getExtras().containsKey("levels"))
startDefaultGame(intent, savedInstanceState);
else
startCustomGame(intent);
} catch (NullPointerException npe) {
startDefaultGame(intent, savedInstanceState);
}
}

Expand Down Expand Up @@ -384,7 +350,7 @@ public void onOptionsMenuClosed(Menu menu) {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
isRunning = false;
numPlayers = 0;
//
// Preserve game information and perform activity cleanup.
//
Expand Down Expand Up @@ -426,7 +392,7 @@ protected void onPause() {
protected void onDestroy() {
//Log.i(TAG, "FrozenBubble.onDestroy()");
super.onDestroy();
isRunning = false;
numPlayers = 0;
cleanUp();
}

Expand Down Expand Up @@ -454,18 +420,19 @@ protected void onSaveInstanceState(Bundle outState) {
*/
@Override
protected void onNewIntent(Intent intent) {
if (null != intent && EDITORACTION.equals(intent.getAction())) {
if (mGameView != null)
mGameView.cleanUp();
mGameView = null;
mGameThread = null;

if (mMultiplayerGameView != null)
mMultiplayerGameView.cleanUp();
mMultiplayerGameView = null;
mMultiplayerGameThread = null;
if (null != intent) {
if (EDITORACTION.equals(intent.getAction())) {
cleanUpGameView();
startCustomGame(intent);
}
else if ((numPlayers != 0) && intent.hasExtra("numPlayers")) {
int newNumPlayers = intent.getIntExtra("numPlayers", 1);

startCustomGame(intent);
if (newNumPlayers != numPlayers) {
cleanUpGameView();
startDefaultGame(intent, null);
}
}
}
}

Expand Down Expand Up @@ -626,6 +593,55 @@ private void startCustomGame(Intent intent) {
playMusic(false);
}

/**
* Method to start a game using default levels, if puzzle game mode
* was selected.
*
* @param intent
* - The intent used to start this activity.
* @param savedInstanceState
* - the bundle of saved state information.
*/
private void startDefaultGame(Intent intent, Bundle savedInstanceState) {
// Default levels.
activityCustomStarted = false;
// Check if this is a single player or multiplayer game.
numPlayers = 1;
if (intent != null) {
if (intent.hasExtra("numPlayers"))
numPlayers = intent.getIntExtra("numPlayers", 1);
}

if (numPlayers > 1) {
mMultiplayerGameView = new MultiplayerGameView(this, numPlayers);
setContentView(mMultiplayerGameView);
mMultiplayerGameView.setGameListener(this);
mMultiplayerGameThread = mMultiplayerGameView.getThread();
if (savedInstanceState != null) {
int savedPlayers = savedInstanceState.getInt("numPlayers");
if (savedPlayers == 2)
mMultiplayerGameThread.restoreState(savedInstanceState);
}
mMultiplayerGameThread.startOpponent();
mMultiplayerGameView.requestFocus();
}
else {
setContentView(R.layout.activity_frozen_bubble);
mGameView = (GameView)findViewById(R.id.game);
mGameView.setGameListener(this);
mGameThread = mGameView.getThread();
if (savedInstanceState != null) {
int savedPlayers = savedInstanceState.getInt("numPlayers");
if (savedPlayers == 1)
mGameThread.restoreState(savedInstanceState);
}

mGameView.requestFocus();
}
setFullscreen();
playMusic(false);
}

private void setFullscreen() {
final int flagFs = WindowManager.LayoutParams.FLAG_FULLSCREEN;
final int flagNoFs = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
Expand Down Expand Up @@ -861,6 +877,14 @@ public void cleanUp() {
myOrientationEventListener = null;
}

cleanUpGameView();

if (myModPlayer != null)
myModPlayer.destroyMusicPlayer();
myModPlayer = null;
}

private void cleanUpGameView() {
if (mGameView != null)
mGameView.cleanUp();
mGameView = null;
Expand All @@ -870,10 +894,6 @@ public void cleanUp() {
mMultiplayerGameView.cleanUp();
mMultiplayerGameView = null;
mMultiplayerGameThread = null;

if (myModPlayer != null)
myModPlayer.destroyMusicPlayer();
myModPlayer = null;
}

/**
Expand Down

0 comments on commit b4bc4bd

Please sign in to comment.