Created
July 21, 2017 04:16
-
-
Save elnikkis/88918d84304d30c6fe05bf59cd7ace3f to your computer and use it in GitHub Desktop.
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
class ScoreBox | |
{ | |
/** | |
* 倒したピンの数(-1は未入力) | |
*/ | |
private int pins; | |
private boolean isFirstBox; | |
public ScoreBox(boolean isFirstBox) | |
{ | |
this.pins = -1; | |
this.isFirstBox = isFirstBox; | |
} | |
public int getPins() | |
{ | |
return this.pins; | |
} | |
public void setPins(int pins) | |
{ | |
this.pins = pins; | |
} | |
} |
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
class ScoreFrame | |
{ | |
private boolean isFinalFrame; | |
private ScoreFrame previousFrame; | |
private ScoreBox[] boxes = new ScoreBox[3]; | |
private int currentBox = 0; | |
private int nextPins = 0; | |
private int nextnextPins = 0; | |
public int getScore() | |
{ | |
int total = 0; | |
for(int i=0; i<2; i++){ | |
int pins = boxes[i].getPins(); | |
if(pins != -1) | |
total += pins; | |
} | |
// スペア | |
if(total == 10){ | |
if(nextPins == -1){ | |
return -1; | |
} | |
else{ | |
total += nextPins; | |
} | |
} | |
// ストライク | |
if(boxes[0].getPins() == 10){ | |
if(nextnextPins == -1){ | |
return -1; | |
} | |
else{ | |
total += nextnextPins; | |
} | |
} | |
return total; | |
} | |
public void setPins(int pins) | |
{ | |
boxes[currentBox].setPins(pins); | |
currentBox++; | |
// 前のフレームに得点の変化を通知 | |
previousFrame.scoreChanged(this); | |
} | |
public void scoreChanged(ScoreFrame nextFrame) | |
{ | |
this.nextPins = next; | |
this.nextnextPins = nextnext; | |
//自身の表示を更新する | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment