Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gkfla668 committed Apr 22, 2022
1 parent 9678bea commit fca482a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/java/controller/LadderGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ private Prizes createPrizes(Players players) {

do {
names = inputPrizes();
prizesCount = Validator.isValidPrizesCount(names.length, players.getPlayerCount());
int playersCount = players.getPlayerCount();
prizesCount = Validator.isValidPrizesCount(names.length, playersCount);
if (!prizesCount) {
OutputView.printPrizeCountErrorMessage(players.getPlayerCount());
OutputView.printPrizeCountErrorMessage(playersCount);
}
} while (!prizesCount);

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/model/GameResultCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ private int upDateLocation(int location, int height) {
}

private int upDateRightLocation(int location, int height) {
boolean rightPoint = lines.get(height).getLine().get(location);
Line line = lines.get(height);
List<Boolean> points = line.getLine();
boolean rightPoint = points.get(location);

if (rightPoint)
location++;
Expand All @@ -63,7 +65,9 @@ private int upDateRightLocation(int location, int height) {
}

private int upDateLeftLocation(int location, int height) {
boolean leftPoint = lines.get(height).getLine().get(location - 1);
Line line = lines.get(height);
List<Boolean> points = line.getLine();
boolean leftPoint = points.get(location - 1);

if (leftPoint)
location--;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/model/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ private List<Boolean> createLine(int width) {
}

private List<Boolean> createValidLine(List<Boolean> points) {
for (int i = 0; i < points.size(); i++)
int width = points.size();

for (int i = 0; i < width; i++)
modifyPoint(points, i);

return points;
}

private void modifyPoint(List<Boolean> points, int pointIdx) {
int lastIdx = points.size() - 1;
if (pointIdx != lastIdx && isValidPoints(points, pointIdx)) {
int width = points.size();
int lastIdx = width - 1;

if (pointIdx != lastIdx && isValidPoints(points, pointIdx))
points.set(pointIdx + 1, false);
}
}

private boolean isValidPoints(List<Boolean> points, int index) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/model/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ public class Validator {

public static boolean isValidPlayerNameLength(String[] names) {
for (String name : names) {
if (name.length() > PLAYER_NAME_STANDARD_LENGTH) {
if (name.length() > PLAYER_NAME_STANDARD_LENGTH)
return false;
}
}
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/GameResultTest.java

This file was deleted.

0 comments on commit fca482a

Please sign in to comment.