Skip to content

Commit

Permalink
refacto(*): Remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rnowif committed Apr 9, 2017
1 parent a7c4d85 commit eb7ab01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 76 deletions.
62 changes: 35 additions & 27 deletions src/main/java/com/adaptionsoft/games/trivia/runner/GameRunner.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@

package com.adaptionsoft.games.trivia.runner;

import com.adaptionsoft.games.uglytrivia.*;

import java.util.List;
import java.util.Random;

import com.adaptionsoft.games.uglytrivia.Game;
import static java.util.Arrays.asList;


public class GameRunner {

private static boolean notAWinner;

public static void main(String[] args) {
Game aGame = new Game();

aGame.add("Chet");
aGame.add("Pat");
aGame.add("Sue");

Random rand = new Random(1L);

do {

aGame.roll(rand.nextInt(5) + 1);

if (rand.nextInt(9) == 7) {
notAWinner = aGame.wrongAnswer();
} else {
notAWinner = aGame.wasCorrectlyAnswered();
}



} while (notAWinner);

}
private static final int NB_CELLS = 12;
private static final int NB_QUESTIONS = 50;
private static final List<Category> CATEGORIES = asList(Category.POP, Category.SCIENCE, Category.SPORTS, Category.ROCK);
private static final List<String> PLAYERS = asList("Chet", "Pat", "Sue");

public static void main(String[] args) {
Game aGame = new Game(
System.out,
new Board(NB_CELLS, CATEGORIES),
new QuestionDeck(NB_QUESTIONS, CATEGORIES),
new PlayerList(PLAYERS)
);

Random rand = new Random(1L);

boolean notAWinner;
do {

aGame.roll(rand.nextInt(5) + 1);

if (rand.nextInt(9) == 7) {
notAWinner = aGame.wrongAnswer();
} else {
notAWinner = aGame.wasCorrectlyAnswered();
}


} while (notAWinner);

}
}
27 changes: 0 additions & 27 deletions src/main/java/com/adaptionsoft/games/uglytrivia/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import static java.util.Arrays.asList;

public class Game {
private static final int NB_CELLS = 12;
private static final int NB_QUESTIONS = 50;
private static final List<Category> CATEGORIES = asList(Category.POP, Category.SCIENCE, Category.SPORTS, Category.ROCK);

private final PrintStream output;
private final Board board;
Expand All @@ -22,30 +19,6 @@ public Game(PrintStream output, Board board, QuestionDeck deck, PlayerList playe
this.players = players;
}

/**
* @deprecated Use constructor with fields instead
*/
@Deprecated
public Game() {
this(
System.out,
new Board(NB_CELLS, CATEGORIES),
new QuestionDeck(NB_QUESTIONS, CATEGORIES),
new PlayerList()
);
}

/**
* @param playerName Name of the player to add
* @deprecated Use the constructor with a predefined list of players
*/
@Deprecated
public void add(String playerName) {
players.add(playerName);
print(playerName + " was added");
print("There are " + players.size() + " players");
}

private void print(String message) {
output.println(message);
}
Expand Down
23 changes: 1 addition & 22 deletions src/main/java/com/adaptionsoft/games/uglytrivia/PlayerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,14 @@ public class PlayerList {
private final List<Player> players = new ArrayList<>();
private int currentPlayerIndex = 0;

/**
* @deprecated Use the constructor with a predefined list of players
*/
@Deprecated
public PlayerList() {
this(new ArrayList<>());
}

public PlayerList(List<String> names) {
names.forEach(this::add);
}

/**
* @deprecated Use the constructor with a predefined list of players
* @param playerName Name of the player to add
*/
@Deprecated
void add(String playerName) {
players.add(new Player(playerName));
names.forEach(name -> players.add(new Player(name)));
}

Player currentPlayer() {
return players.get(currentPlayerIndex);
}

int size() {
return players.size();
}

Player nextPlayer() {
currentPlayerIndex = (currentPlayerIndex + 1) % players.size();
return players.get(currentPlayerIndex);
Expand Down

0 comments on commit eb7ab01

Please sign in to comment.