Last active
July 10, 2023 08:54
-
-
Save drobune/b1a091088a150114ab421e88cb4cd174 to your computer and use it in GitHub Desktop.
アジャイル本のボウリング実装コード
This file contains hidden or 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
// Game.java- | |
public class Game | |
{ | |
public int score() | |
return scoreForFrame (its Current Frame); | |
${ | |
} | |
public void add (int pins) | |
{ | |
} | |
private void adjust Current Frame (int pins) laborios | |
{ | |
if (last Ball InFrame (pins)) | |
advance Frame(); | |
} | |
itsscorer. addThrow (pins); | |
adjust Current Frame (pins); | |
} | |
else | |
firstThrowInFrame = false; | |
private boolean lastBallInFrame (int pins) | |
{ | |
return strike (pins) || !firstThrowInFrame; | |
private boolean strike(int pins) | |
{ | |
return (firstThrowInFrame && pins == 10); | |
private void advance Frame() | |
{ | |
itsCurrent Frame = Math.min(10, its Current Frame + 1); | |
public int score ForFrame (int the Frame) | |
{ | |
return its Scorer.score ForFrame (theFrame); | |
} | |
} | |
} | |
// Scorer.java-- | |
public class Scorer | |
{ | |
private int itsCurrent Frame = 0; | |
private boolean firstThrowInFrame = true; | |
private Scorer itsScorer = new Scorer(); | |
} | |
public void addThrow (int pins) | |
{ | |
its Throws [its Current Throw++] | |
} | |
public int scoreForFrame (int the Frame) | |
{ | |
ball = 0; | |
int score=0; | |
for (int current Frame = 0; | |
{ | |
current Frame < the Frame; | |
current Frame++) | |
if (strike()) | |
{ | |
} | |
else if (spare() ) | |
{ | |
} | |
score + 10 + nextTwoBalls ForStrike (); | |
ball++; | |
score + 10 + nextBallForSpare(); | |
ball+=2; | |
} wold | |
else | |
{ | |
score + twoBallsInFrame(); | |
ball+=2; | |
} | |
return score; | |
private boolean strike () | |
{ | |
= pins; | |
return itsThrows [ball] | |
== | |
10; | |
private boolean spare() | |
{ | |
} | |
private int nextBallForSpare() | |
{ | |
return its Throws [ball+2]; | |
} | |
return its Throws [ball+1] + itsThrows [ball+2]; | |
private int twoBalls InFrame() | |
{ | |
return its Throws [ball] + its Throws [ball+1]; | |
} | |
} | |
private int ball; | |
private int[] itsThrows = new int[21]; | |
private int itsCurrentThrow = 0; | |
} | |
return (its Throws [ball] + its Throws [ball+1]); | |
private int nextTwoBallsForStrike () | |
== | |
10; | |
} | |
private int nextBallForSpare() | |
{ | |
return its Throws [ball+2]; | |
} | |
return its Throws [ball+1] + itsThrows [ball+2]; | |
private int twoBalls InFrame() | |
{ | |
return its Throws [ball] + its Throws [ball+1]; | |
} | |
} | |
private int ball; | |
private int[] itsThrows = new int[21]; | |
private int itsCurrentThrow = 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment