CardGame -> Game

master
Saša Kocić 6 years ago
parent 15b740c06f
commit 5b0b75045a

@ -1,14 +1,14 @@
# Card Game # Card Game
```plantuml ```plantuml
CardGame o-- Pile Game o-- Pile
class CardGame { class Game {
int numberOfPlayers; int numberOfPlayers;
public Player[] players; public Player[] players;
Pile pot; Pile pot;
Pile draws; Pile draws;
public CardGame(int numberOfCards, int numberOfPlayers) public Game(int numberOfCards, int numberOfPlayers)
private void createPlayersWithCards(int numberOfPlayers, Pile deck) private void createPlayersWithCards(int numberOfPlayers, Pile deck)
public void play() public void play()
} }

@ -1,6 +1,6 @@
import java.util.ArrayList; import java.util.ArrayList;
public class CardGame { public class Game {
Player[] players; Player[] players;
final Pile pot = new Pile(); final Pile pot = new Pile();
final Pile draws = new Pile(); final Pile draws = new Pile();
@ -10,7 +10,7 @@ public class CardGame {
* @param numberOfCards Total number of cards * @param numberOfCards Total number of cards
* @param numberOfPlayers Total number of players * @param numberOfPlayers Total number of players
*/ */
public CardGame(int numberOfCards, int numberOfPlayers) { public Game(int numberOfCards, int numberOfPlayers) {
Pile deck = Pile.createDeck(numberOfCards); Pile deck = Pile.createDeck(numberOfCards);
createPlayersWithCards(numberOfPlayers, deck); createPlayersWithCards(numberOfPlayers, deck);
this.numberOfPlayers = numberOfPlayers; this.numberOfPlayers = numberOfPlayers;

@ -3,26 +3,26 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class CardGameTest { class GameTest {
CardGame cardGame; Game game;
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
@BeforeEach @BeforeEach
void setUp() { void setUp() {
cardGame = new CardGame(10, 2); game = new Game(10, 2);
} }
@Test @Test
void createDeck() { void createDeck() {
assertEquals(2, cardGame.players.length); assertEquals(2, game.players.length);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
assertEquals(20, cardGame.players[i].drawPile.size()); assertEquals(20, game.players[i].drawPile.size());
} }
} }
@Test @Test
void play() { void play() {
cardGame.play(); game.play();
} }
} }

@ -4,8 +4,8 @@
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
CardGame cardGame = new CardGame(10, 2); Game game = new Game(10, 2);
cardGame.play(); game.play();
Out.toConsole(); System.out.print(Out.get());
} }
} }

@ -1,18 +1,24 @@
import java.util.ArrayList;
public class Out { public class Out {
static final String[] output = new String[50000]; static final ArrayList<String> output = new ArrayList<>();
static int line = 0;
private Out() { throw new IllegalStateException("Utility class"); }
public static void println(String string) { public static void println(String string) {
output[line++] = string; output.add(string);
} }
public static void println() { public static void println() {
output[line++] = ""; println("");
} }
public static void toConsole() { public static String get() {
for (int i = 0; i < line; i++) { StringBuilder string = new StringBuilder();
System.out.println(output[i]); for (String s : output) {
string.append(s);
string.append("\n");
} }
return string.toString();
} }
} }

@ -1,6 +0,0 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class PlayerTest {
}
Loading…
Cancel
Save