Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
Fixed computer redoing his round every time reopen app
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkjenn committed Apr 25, 2014
1 parent 2a8a75d commit 2afd76e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
11 changes: 6 additions & 5 deletions Ambiguous/src/no/hiof/android/ambiguous/GameMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,10 @@ private void checkDead() {
state = State.GAME_OVER;
}
}

public void setStateAndNotify(State state)
{

public void setStateAndNotify(State state) {
this.state = state;
notifyStateChange();
notifyStateChange();
}

/**
Expand Down Expand Up @@ -357,7 +356,9 @@ public void clearGameMachineListener() {
}

public void setTurnChangeListener(TurnChangeListener listener) {
turnChangeListeners.add(listener);
if (!turnChangeListeners.contains(listener)) {
turnChangeListeners.add(listener);
}
}

public void removeTurnChangeListener(TurnChangeListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,30 @@ public class SinglePlayerFragment extends Fragment {
@Override
public void onStart() {
super.onStart();
if (getArguments() != null) {
resumeGame(getArguments());
}
sds = new SessionDataSource((Db.getDb(getActivity()
.getApplicationContext()).getWritableDatabase()));

setupController();

startGameMachine();
}

void startGameMachine() {
@Override
public void onResume() {
super.onResume();
if (getArguments() != null) {
resumeGame(getArguments());
}
GameActivity.gameMachine.setTurnChangeListener(aiController);

GameActivity.gameMachine.startGame(GameActivity.gameMachine.state);
}


void setupController() {
aiController = new AIController(GameActivity.gameMachine.opponent,
GameActivity.gameMachine.player,
GameActivity.opponentController);
GameActivity.gameMachine.setTurnChangeListener(aiController);
if (aiController == null) {
aiController = new AIController(GameActivity.gameMachine.opponent,
GameActivity.gameMachine.player,
GameActivity.opponentController);
}
}

private void resumeGame(Bundle extras) {
Expand Down

0 comments on commit 2afd76e

Please sign in to comment.