Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0a06bdd
Create Frame class with functions that check for its status
krapeaj Apr 13, 2018
16a78c6
Create abstractions of Player and BowlingGame
krapeaj Apr 13, 2018
1012dbc
Add input validation
krapeaj Apr 13, 2018
90e72f9
Fix bug in input validation
krapeaj Apr 13, 2018
5d046ef
Create ScoreCalculator class
krapeaj Apr 13, 2018
8fb8f8d
Add functions to initialize game
krapeaj Apr 14, 2018
391deba
Add functions that calculate frame final score
krapeaj Apr 15, 2018
c34207f
Create toString methods
krapeaj Apr 16, 2018
404bd3e
Complete printer function for marking figures
krapeaj Apr 16, 2018
5092d98
Restart project and implement logic that checks whether each bowl/fra…
krapeaj Apr 17, 2018
7e472b9
Add functions that check for strike and spare
krapeaj Apr 17, 2018
10cac3b
Restart project and abstract classes frames and bowls
krapeaj Apr 17, 2018
c13bdf4
Add function that updates the status of the corresponding bowl object
krapeaj Apr 18, 2018
873c8fe
Create Frame interface
krapeaj Apr 18, 2018
9f965b9
Restart and create frame states
krapeaj Apr 18, 2018
bc2cf35
Add function to differentiate between firstbowl and secondbowl
krapeaj Apr 18, 2018
67fb539
Set up status changing logic and score updating logic
krapeaj Apr 18, 2018
9242e9a
Restructure packages
krapeaj Apr 19, 2018
ae3553f
Add function that calculates additional score for each frame
krapeaj Apr 19, 2018
40698e6
Recreate function that calculates addition scores
krapeaj Apr 19, 2018
4c91958
Refactor code to delegate score update to status object
krapeaj Apr 19, 2018
ef277c0
Refactor code
krapeaj Apr 19, 2018
1bb91b0
Minor type fix
krapeaj Apr 19, 2018
19ac6fa
Have Frames keep the instance of the next frame
krapeaj Apr 19, 2018
dd87693
Refactor code
krapeaj Apr 19, 2018
02235a0
Add override annotations
krapeaj Apr 19, 2018
d5c71a0
Create player class that implements printable interface
krapeaj Apr 19, 2018
0ba8179
Override toString methods
krapeaj Apr 19, 2018
3d7dfc3
Add user prompt, formatter, and main
krapeaj Apr 20, 2018
0a5950a
Override last frames toString method
krapeaj Apr 20, 2018
eb0154c
Create various status classes for last frame
krapeaj Apr 20, 2018
58f503b
Add separate status for last frame
krapeaj Apr 20, 2018
fbf082d
Add function that calculates last frame score
krapeaj Apr 20, 2018
c31e0f3
Add override annotations
krapeaj Apr 20, 2018
7320715
Complete draft fulfilling step2 requirements
krapeaj Apr 20, 2018
21c2507
Fix bugs that made the program unable to exit
krapeaj Apr 20, 2018
f76821e
Include frame number when prompting for bowl
krapeaj Apr 20, 2018
5ba2304
Replace unnecessary frame list with just one frame instance
krapeaj Apr 20, 2018
713ba81
Create wrapper class frames
krapeaj Apr 20, 2018
68b3119
Create score class for last frame
krapeaj Apr 20, 2018
e830254
Add score calculation after each bowl
krapeaj Apr 21, 2018
fc4f217
Finish implementing score calculation - bug exists for double strike
krapeaj Apr 21, 2018
e3cca8f
Fix bug that caused miscalculation
krapeaj Apr 21, 2018
a1066b6
Fix bug that did not show score for strike frames
krapeaj Apr 21, 2018
8741866
Fix bug in determining whether the game has ended
krapeaj Apr 21, 2018
58b3f55
Add separate classes for the last frame
krapeaj Apr 22, 2018
6aedf10
Remove unnecessary code is last frame status implementations
krapeaj Apr 22, 2018
bb535ee
Complete logic that passes on accumulative score on normal frames
krapeaj Apr 22, 2018
dc2619e
Complete calculating accumulative total score for whole
krapeaj Apr 22, 2018
cb0730e
Remove unnecessary code and use constants to represent literals
krapeaj Apr 22, 2018
e2d95bb
Restructure packages and rename classes
krapeaj Apr 22, 2018
efe63ab
Use interface frame instead of an abstract class frame
krapeaj Apr 22, 2018
958684e
Improve way of determining the end of game
krapeaj Apr 23, 2018
5efd2a7
Remove unncessary score object in frame
krapeaj Apr 23, 2018
ec1322b
Remove duplicate classes and restructure packages
krapeaj Apr 23, 2018
1c46fc6
Fix bug where final score would not show
krapeaj Apr 23, 2018
d4afd9f
Remove unnecessary logic for calculating the total score
krapeaj Apr 23, 2018
97115d9
Replace hard-coded numbers with constants and use void instead of boo…
krapeaj Apr 23, 2018
d4fea40
Add input validation by creating Pins class
krapeaj Apr 23, 2018
8fad002
Complete tests and refactor code
krapeaj Apr 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/main/java/bowling/Main.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
package bowling;

import bowling.view.BowlingGame;
import bowling.domain.Player;
import bowling.domain.Utils.Validator;

import static bowling.view.Prompter.*;
import bowling.view.ResultView;
import bowling.view.UserPrompt;

public class Main {
public static void main(String[] args) {
Player player = getPlayer();
BowlingGame game = new BowlingGame(player);

game.startGame();
String name = getUserName();
Player player = new Player(name);
startBowl(player);
}

private static Player getPlayer() {
private static String getUserName() {
try {
String playerName = promptForName();
Validator.validateName(playerName);
return new Player(playerName);
return UserPrompt.promptUserForName();
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
return getPlayer();
return getUserName();
}
}

private static void startBowl(Player player) {
while (!player.isDone()) {
try {
int pins = UserPrompt.promptUserForBowl(player.getCurrentFrameNumber());
player.bowl(pins);
ResultView.printScoreBoard(player);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
}
46 changes: 31 additions & 15 deletions src/main/java/bowling/domain/Player.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
package bowling.domain;

import bowling.domain.Utils.Formatter;
import bowling.domain.frame.Frames;
import bowling.domain.frame.frame;
import bowling.domain.frame.NormalFrame;
import bowling.domain.util.Formatter;

public class Player {
private final Frames frames = new Frames();
private final String playerName;
public class Player implements Printable {
private static final int FIRST = 1;
private static final int INITIAL = 0;

public Player(String playerName) {
this.playerName = playerName;
private final String name;
private final frame frames;

public Player(String name) {
this.name = name;
this.frames = new NormalFrame(FIRST);
}

public void bowl(int pins) {
frames.bowl(pins);
}

public boolean throwBall(int frameNumber, int pinsKnocked) {
return frames.knockPins(frameNumber, pinsKnocked);
public boolean isDone() {
return frames.isLast();
}

public boolean isStrike(int frameNumber) {
return frames.isStrike(frameNumber);
public int getCurrentFrameNumber() {
return frames.getFrameNumber();
}

public boolean isSpare(int frameNumber) {
return frames.isSpare(frameNumber);
@Override
public String convertStatusToPrintable() {
return "|"
+ Formatter.formatFrame(name)
+ "|"
+ frames.getPrintableStatus();
}

@Override
public String toString() {
return "|" + Formatter.formatFrame(" " + playerName) + frames.toString();
public String convertScoreToPrintable() {
return "|"
+ Formatter.formatFrame("")
+ "|"
+ frames.getPrintableScore(INITIAL);
}
}
8 changes: 8 additions & 0 deletions src/main/java/bowling/domain/Printable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package bowling.domain;

public interface Printable {

String convertStatusToPrintable();

String convertScoreToPrintable();
}
24 changes: 0 additions & 24 deletions src/main/java/bowling/domain/Utils/Formatter.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/bowling/domain/Utils/Validator.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/bowling/domain/frame/Frame.java

This file was deleted.

50 changes: 0 additions & 50 deletions src/main/java/bowling/domain/frame/Frames.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/bowling/domain/frame/LabelFrame.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/main/java/bowling/domain/frame/LabelFrames.java

This file was deleted.

63 changes: 36 additions & 27 deletions src/main/java/bowling/domain/frame/LastFrame.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
package bowling.domain.frame;

import bowling.domain.score.BonusScore;
import bowling.domain.score.Scores;

public class LastFrame implements Frame{
private Scores scores = new Scores();
private BonusScore bonusScore = new BonusScore();

public boolean knockPins(int pinsKnocked) {
if (!scores.firstThrowIsPlayed()) {
scores.updateFirstThrow(pinsKnocked);
return true;
}
if (!scores.secondThrowIsPlayed() && !scores.isStrike()) {
scores.updateSecondThrow(pinsKnocked);
return true;
}
if (!bonusScore.isPlayed()) {
bonusScore.updateScore(pinsKnocked);
return true;
}
return false;
import bowling.domain.frame.status.LastFrameStatus;
import bowling.domain.frame.score.Score;
import bowling.domain.util.Formatter;

public class LastFrame implements frame {
private static final int LAST = 10;

private final LastFrameStatus status = new LastFrameStatus();

@Override
public int getFrameNumber() {
return LAST;
}

public boolean isStrike() {
return scores.isStrike();
@Override
public void bowl(int pins) {
status.bowl(pins);
}

@Override
public boolean isLast() {
return status.isComplete();
}

public boolean isSpare() {
return scores.isSpare();
@Override
public String getPrintableStatus() {
return Formatter.formatFrame(status.toString()) + "|";
}

@Override
public String getPrintableScore(int total) {
Score score = status.createScore();
return score.getScore(total) + "|";
}

@Override
public void calculateAdditionalScore(Score prevScore) {
status.updateScoresFromPreviousFrames(prevScore);
}

@Override
public String toString() {
return " " + scores.toString() + bonusScore.toString();
public void updateScoreFromPrevPrev(Score prevPrev) {
status.updateScoresFromPreviousFrames(prevPrev);
}
}
Loading