Skip to content

perfect-game/score-calculator

Repository files navigation

Score Calculator

GitHub Workflow Status GitHub package.json version

Score Calculator is a bowling score calculator engine that supports two scoring ways: Traditional Scoring and Current Frame Scoring.

APIs

TraditionalScoreManager

You can use TraditionalScoreManager class with TranditionalScoringFrame class.

new TraditionalScoreManager()
  .push(new TraditionalScoringFrame().setFirstPitch(10)) // Striked
  .push(new TraditionalScoringFrame().setFirstPitch(5).setSecondPitch(5)) // Spared
  .push(new TraditionalScoringFrame().setFirstPitch(9)) // Opened Frame
  .push(new TraditionalScoringFrame()) // Gutters
  .push(new TraditionalScoringFrame().setFirstPitch(10))
  .push(new TraditionalScoringFrame().setFirstPitch(5).setSecondPitch(5))
  .push(new TraditionalScoringFrame().setFirstPitch(9))
  .push(new TraditionalScoringFrame())
  .push(new TraditionalScoringFrame())
  .push(
    new TranditionalScoringFrame()
      .setFirstPitch(10)
      .setSecondPitch(10)
      .setThirdPitch(10)
  ) // There is a third pitching at tenth frame.
  .totalScore // === 126

CurrentFrameScoreManager

You can use CurrentFrameScoreManager class with CurrentFrameScoringFrame class.

new CurrentFrameScoreManager()
  .push(new CurrentFrameScoringFrame().setFirstPitch(10)) // Striked
  .push(new CurrentFrameScoringFrame().setFirstPitch(5).setSecondPitch(5)) // Spared
  .push(new CurrentFrameScoringFrame().setFirstPitch(9)) // Opened Frame
  .push(new CurrentFrameScoringFrame()) // Gutters
  .push(new CurrentFrameScoringFrame().setFirstPitch(10))
  .push(new CurrentFrameScoringFrame().setFirstPitch(5).setSecondPitch(5))
  .push(new CurrentFrameScoringFrame().setFirstPitch(9))
  .push(new CurrentFrameScoringFrame())
  .push(new CurrentFrameScoringFrame())
  .push(new CurrentFrameScoringFrame().setFirstPitch(10))
  .totalScore // === 138