Skip to content

Instantly share code, notes, and snippets.

@drobune
Last active July 10, 2023 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drobune/b1a091088a150114ab421e88cb4cd174 to your computer and use it in GitHub Desktop.
Save drobune/b1a091088a150114ab421e88cb4cd174 to your computer and use it in GitHub Desktop.
アジャイル本のボウリング実装コード
// 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