No winner implemented

master
Saša Kocić 6 years ago
parent eeb29d96dc
commit fec9f2512b

@ -2,7 +2,7 @@ import java.util.ArrayList;
public class CardGame { public class CardGame {
public Player[] players; public Player[] players;
Pile pot; Pile pot = new Pile();
Card[] draws; Card[] draws;
/** /**
@ -18,7 +18,6 @@ public class CardGame {
for (int i = 0; i < numberOfPlayers; i++) { for (int i = 0; i < numberOfPlayers; i++) {
players[i] = new Player(String.valueOf(i), deck.getCardsForPlayer(cardsPerPlayer)); players[i] = new Player(String.valueOf(i), deck.getCardsForPlayer(cardsPerPlayer));
} }
pot = new Pile();
} }
public Pile createDeck(int numberOfCards) { public Pile createDeck(int numberOfCards) {
@ -54,13 +53,24 @@ public class CardGame {
if (max.number < drawn[i].number) { if (max.number < drawn[i].number) {
maxIndex = i; maxIndex = i;
max = drawn[maxIndex]; max = drawn[maxIndex];
} else if (max.number == drawn[i].number) {
// what if there is no winner?
} }
} }
System.out.printf("Player %d wins this round\n\n", maxIndex); if (uniqueMaximum(drawn, max, maxIndex)) {
players[maxIndex].discardPile.addAll(pot); System.out.printf("Player %d wins this round\n\n", maxIndex);
pot.clear(); players[maxIndex].discardPile.addAll(pot);
pot.clear();
} else {
System.out.printf("No winner in this round\n\n");
}
}
private boolean uniqueMaximum(Card[] draws, Card max, int maxIndex) {
for (int i = 0; i < draws.length; i++) {
if (maxIndex != i && max.number == draws[i].number) {
return false;
}
}
return true;
} }
private boolean noWinner() { private boolean noWinner() {

Loading…
Cancel
Save