-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a59b62
commit 04fa075
Showing
12 changed files
with
154 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class DecisionMakingState implements LaneState { | ||
private int result; | ||
|
||
@Override | ||
public void handle(Lane lane){ | ||
if (result == 1) { // yes, want to play again | ||
lane.resetScores(); | ||
lane.resetBowlerIterator(); | ||
lane.setState(lane.gameInProgressState); | ||
lane.handleState(); | ||
} else if (result == 2) { // no, dont want to play another game | ||
lane.printEndGameReportAndNotifyMembers(); | ||
lane.setState(lane.noPartyAssignedState); | ||
lane.handleState(); | ||
} | ||
} | ||
|
||
public void setResult(int result){ | ||
this.result = result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public class EndOfGameState implements LaneState { | ||
@Override | ||
public void handle(Lane lane){ | ||
int result = lane.promptEndGame(); | ||
((DecisionMakingState)lane.decisionMakingState).setResult(result); | ||
lane.setState(lane.decisionMakingState); | ||
lane.handleState(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class GameInProgressState implements LaneState { | ||
@Override | ||
public void handle(Lane lane){ | ||
if (lane.getBowlIterator().hasNext()) { | ||
lane.prepareNextThrow(); | ||
lane.recordFinalScore(); | ||
lane.resetThrow(); | ||
} else { | ||
lane.proceedToNextFrame(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public interface LaneState { | ||
public void handle(Lane lane); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
public class NoPartyAssignedState extends Thread implements LaneState { | ||
@Override | ||
public void handle(Lane lane){ | ||
if(lane.isPartyAssigned() == true){ | ||
lane.setState(lane.partyAssignedState); | ||
lane.handleState(); | ||
} | ||
else{ | ||
doSleep(10); | ||
} | ||
} | ||
|
||
private void doSleep(int millis){ // 중복된 sleep()을 메소드로 변경 | ||
try{ | ||
sleep(millis); | ||
} catch (Exception e) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class PartyAssignedState implements LaneState { | ||
|
||
|
||
@Override | ||
public void handle(Lane lane){ | ||
if(lane.isGameFinished() == false){ | ||
lane.setState(lane.pauseGameState); | ||
lane.handleState(); | ||
} | ||
else{ | ||
lane.setState(lane.endOfGameState); | ||
lane.handleState(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class PauseGameState extends Thread implements LaneState { | ||
@Override | ||
public void handle(Lane lane){ | ||
while(lane.isGameHalted()){ | ||
doSleep(10); | ||
} | ||
lane.setState(lane.gameInProgressState); | ||
lane.handleState(); | ||
} | ||
|
||
private void doSleep(int millis){ // 중복된 sleep()을 메소드로 변경 | ||
try{ | ||
sleep(millis); | ||
} catch (Exception e) {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public interface ScoreCalculatorStrategy { | ||
|
||
} |