Card_Class & Deck_Class (schuffleDeck-methode) & Player_Class

MAIN
wafialwakil 2024-03-04 12:16:22 +01:00
parent bee12748e7
commit 4f7b2072c6
5 changed files with 74 additions and 1 deletions

View File

@ -3,12 +3,21 @@ package Infrastructur;
public class Card { public class Card {
private int wert; private int wert;
private int id;
private CardKind kartenTyp; private CardKind kartenTyp;
// public Card (int id) {
// this.id = id;
// }
public void setWert(int wert) { public void setWert(int wert) {
this.wert = wert; this.wert = wert;
} }
public void setID(int id) {
this.id = id;
}
public void setKartenTyp(CardKind kartenTyp) { public void setKartenTyp(CardKind kartenTyp) {
this.kartenTyp = kartenTyp; this.kartenTyp = kartenTyp;
} }
@ -17,6 +26,10 @@ public class Card {
return wert; return wert;
} }
public int getID() {
return id;
}
public CardKind getKartenTyp() { public CardKind getKartenTyp() {
return kartenTyp; return kartenTyp;
} }

View File

@ -1,6 +1,7 @@
package Infrastructur; package Infrastructur;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public class Deck extends Card{ public class Deck extends Card{
@ -16,4 +17,9 @@ public class Deck extends Card{
} }
} }
public List<Card> shuffleDeck(List<Card> deck) {
Collections.shuffle(deck);
return deck;
}
} }

View File

@ -5,7 +5,8 @@ public class NormalCard extends Card{
private CardKind[] laufKarten = {CardKind.TWO, CardKind.THREE, CardKind.SIX, CardKind.EIGHT, CardKind.NINE, private CardKind[] laufKarten = {CardKind.TWO, CardKind.THREE, CardKind.SIX, CardKind.EIGHT, CardKind.NINE,
CardKind.QUEEN}; CardKind.QUEEN};
public NormalCard(CardKind kartenTyp) { public NormalCard(int id, CardKind kartenTyp) {
// super(id);
setKartenTyp(kartenTyp); setKartenTyp(kartenTyp);
// Setze den Wert basierend auf dem KartenTyp (z.B., TWO = 2, THREE = 3, etc.) // Setze den Wert basierend auf dem KartenTyp (z.B., TWO = 2, THREE = 3, etc.)
setWert(kartenTyp.ordinal() + 2); setWert(kartenTyp.ordinal() + 2);

View File

@ -0,0 +1,52 @@
package Infrastructur;
public class Player {
private int id;
private String name;
private Card[] handCards;
public Player (int id, String name) {
this.id = id;
this.name = name;
}
public int getID() {
return id;
}
public String getName() {
return name;
}
public void setID (int id) {
this.id = id;
}
public void setName (String name) {
this.name = name;
}
public Card[] getHandCards () {
return handCards;
}
public Card playCard (int id) throws Exception {
if ((handCards == null) || (id < 0) || (id >= handCards.length) || (handCards[id] == null)) {
System.err.println("Invalid Card!");
//TODO Exception Schreiben InvalidCardException
throw new Exception();
}
Card playedCard = handCards[id];
return playedCard;
}
@Override
public String toString() {
return "ID: " + this.getID() + ", Name: " + this.name;
}
}

View File

@ -7,6 +7,7 @@ public class SpecialCard extends Card{
public SpecialCard(CardKind kartenTyp) { public SpecialCard(CardKind kartenTyp) {
// super(id);
setKartenTyp(kartenTyp); setKartenTyp(kartenTyp);
} }