Deck_Class (createAndShuffleDeck-method , getTopCard-method &

getNumberOfCards-method)
MAIN
wafialwakil 2024-03-05 10:50:41 +01:00
parent 4f7b2072c6
commit fae889e17f
2 changed files with 117 additions and 13 deletions

View File

@ -1,8 +1,100 @@
package GameFunctionality; package GameFunctionality;
import Infrastructur.Gameboard; import java.util.ArrayList;
import Infrastructur.Card;
import Infrastructur.Deck;
import Infrastructur.Player;
public class Gamesystem { public class Gamesystem {
private final static int CARDS_PRO_ROUND = 4;
private boolean gameIsGoing = false;
private boolean hasGameEnded = false;
private int playerCounter = 0;
private int playerID = 1;
private ArrayList<Player> playersList= new ArrayList<>();
private ArrayList<ArrayList<Card>> playerCards = new ArrayList<>();
private ArrayList <Card> playedCards;
private Player playingPlayer;
private Deck deck;
public Gamesystem () {
}
public void addPlayer(String name) {
Player player = new Player(playerID, name);
playersList.add(player);
playerCounter++;
// if(playersList.size()>0){
playerID++;
// }
}
public void removePlayer(int id_player) throws Exception {
for(Player plr : playersList) {
if(plr.getID() == id_player) {
playersList.remove(plr);
playerCounter--;
return;
}
}
// TODO Exception schreiben für nicht existierende ID's
throw new Exception();
}
public String[] getAllPlayers() {
String[] allPlayers = new String [playersList.size()];
for(int i=0; i<playersList.size(); i++) {
allPlayers[i] = "ID: " + playersList.get(i).getID() +
", Name: " + playersList.get(i).getName();
}
return allPlayers;
}
// TODO
public String getTheWinner() {
return null;
}
public boolean isTheGameGoing() {
if(deck.getNumberOfCards() == 0) {
hasGameEnded = true;
}
return hasGameEnded;
}
public void handOutCards() throws Exception {
playerCards = new ArrayList<>();
deck.createAndShuffleDeck();
for (int i=0; i<CARDS_PRO_ROUND; i++) {
for(int j=0; j<playerCounter; j++) {
Card card = deck.getTopCard();
if(card != null) {
playerCards.get(i).add(card);
}
else {
// TODO Exception schreiben DeckIsEmpty
throw new Exception();
}
}
}
}
public void playCard (int id_Card) {
boolean playerHasCard = false;
}
public void startGame() {
}
} }

View File

@ -8,18 +8,30 @@ public class Deck extends Card{
private List<Card> deck; private List<Card> deck;
public Deck() { public Deck() {
deck = new ArrayList<>();
for (CardKind kartenTyp : CardKind.values()) {
for (int i = 0; i < 4; i++) {
deck.add(new Card());
}
}
}
public List<Card> shuffleDeck(List<Card> deck) { }
Collections.shuffle(deck);
return deck; public List<Card> createAndShuffleDeck() {
} deck = new ArrayList<>();
for (CardKind kartenTyp : CardKind.values()) {
for (int i = 0; i < 4; i++) {
deck.add(new Card());
}
}
Collections.shuffle(deck);
return deck;
}
public Card getTopCard() {
if(!deck.isEmpty()) {
return deck.remove(0);
}
return null;
}
public int getNumberOfCards() {
return deck.size();
}
} }