Funktionen Implementiert, Tests angepasst, Java Doc added

This commit is contained in:
Georg Reisinger 2020-10-18 12:35:58 +02:00
parent 061a978f6c
commit 95873d7e6d
23 changed files with 810 additions and 158 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
.idea/compiler.xml .idea/compiler.xml
*.lst

View File

@ -1,37 +1,118 @@
/**
* Object einer Card
*/
public class Card { public class Card {
private String name;
private double damage;
private ElementTyp elementTyp;
private CardType cardType;
/**
* Erstellt eine neue Card mit gegebenen Eigenschaften
* @param name Name der Card
* @param damage Damage den die Card macht
* @param elementTyp ElementType der Card
* @param cardType CardType der Card
*/
public Card(String name, double damage, ElementTyp elementTyp, CardType cardType) { public Card(String name, double damage, ElementTyp elementTyp, CardType cardType) {
this.name = name;
this.damage = damage;
this.elementTyp = elementTyp;
this.cardType = cardType;
} }
/**
* Holt den Namen der Card
* @return Name der Card
*/
public String getName() { public String getName() {
return ""; return this.name;
} }
public int getDamage() { /**
return 0; * Holt den Damage der Card
* @return Damage der Card
*/
public double getDamage() {
return this.damage;
} }
/**
* Holt den ElementType der Card
* @return ElementType der Card
*/
public ElementTyp getElementTyp() { public ElementTyp getElementTyp() {
return null; return this.elementTyp;
} }
/**
* Holt den CardType der Card
* @return CardType der Card
*/
public CardType getCardType() { public CardType getCardType() {
return null; return this.cardType;
} }
public EffectivnessType getEffectivenessAgainst() { /**
return null; * Berechnet die Wirksamkeit gegen eine Andere card. Die Card im Parameter wird angegriffen
* @param toCeck Card gegen welche die Wirksamkeit geprüft werden soll
* @return Gibt die Wirksamkeit zurück
* @throws InternalError Wenn die Effectifeness von den 2 Cards nicht berechnet werden kann
*/
public EffectivnessType getEffectivenessAgainst(Card toCeck) {
if(toCeck.getCardType() == CardType.MONSTER){
if(this.cardType == CardType.MONSTER){
return EffectivnessType.NOEFFECT;
}else if (this.cardType == CardType.SPELL){
}
}else if (toCeck.getCardType() == CardType.SPELL){
if ((toCeck.getElementTyp() == ElementTyp.FIRE && this.elementTyp == ElementTyp.WATER) || (toCeck.getElementTyp() == ElementTyp.NORMAL && this.elementTyp == ElementTyp.FIRE) || (toCeck.getElementTyp() == ElementTyp.WATER && this.elementTyp == ElementTyp.NORMAL)){
return EffectivnessType.EFFECTIVE;
}else if (this.elementTyp == ElementTyp.FIRE && toCeck.getElementTyp() == ElementTyp.WATER){
return EffectivnessType.NOTEFFECTIVE;
}else if ((toCeck.getElementTyp() == ElementTyp.NORMAL && this.cardType == CardType.MONSTER && this.elementTyp == ElementTyp.NORMAL)){
return EffectivnessType.NOEFFECT;
}
}
throw new InternalError("Konnte die Effectiveness von den Cards nicht berechnen");
} }
public boolean setName(String neuerName) { /**
return false; * Setztden namen der Card
* @param neuerName Name der Card
*/
public void setName(String neuerName) {
this.name = name;
} }
public boolean setDamage(int damage) { /**
return false; * Setzt den Damage der Card
* @param damage Der Damage
*/
public void setDamage(int damage) {
this.damage = damage;
} }
public boolean setElementType(ElementTyp elementTyp) { /**
return false; * Setzt den ElementType der Card
* @param elementTyp Der ElementType
*/
public void setElementType(ElementTyp elementTyp) {
this.elementTyp = elementTyp;
}
/**
* Testet ob die beiden Karten gleich sind
* @param card Card die geprüft werden soll
* @return True wenn die Karten übereinstimmen
*/
public boolean equals(Card card){
if(card == null) return false;
if(this.name == card.getName() && this.cardType == card.getCardType() && this.elementTyp == card.getElementTyp() && this.damage == card.getDamage()){
return true;
}else {
return false;
}
} }
} }

View File

@ -1,23 +1,78 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Verwaltet eine Liste vo Cards
*/
public class Cards { public class Cards {
public Cards(ArrayList<Card> cardsArrayList) { private ArrayList<Card> cards;
/**
* Erstellt ein nues obj mit gegebenen Karten
* @param cardsArrayList Die Cards zum erstellen des Obj
*/
public Cards(ArrayList<Card> cardsArrayList) {
this.cards = cardsArrayList;
} }
/**
* Erstellt ein neues Obj ohne Cards
*/
public Cards() { public Cards() {
} }
/**
* Fügt eine neue Card hinzu
* @param newCard neue Card
*/
public void addCard(Card newCard) { public void addCard(Card newCard) {
this.cards.add(newCard);
} }
/**
* Holt alle Cards
* @return Alle Cards
*/
public ArrayList<Card> getCards() { public ArrayList<Card> getCards() {
return null; return this.cards;
} }
public boolean delCard(Card delCard) { /**
return false; * Löscht die gegebene Card
* @param delCard Card zum löschen
*/
public void delCard(Card delCard) {
this.cards.removeIf(obj -> obj.equals(delCard));
}
/**
* Prüft ob eine Card in den Cards vorhanden ist
* @param toCeck Card nach der in den Cards gesucht werden soll
* @return True wenn die Card in den Cards ist
*/
public boolean containsCard(Card toCeck){
AtomicBoolean returnval = new AtomicBoolean(false);
this.cards.forEach(item -> {
if(item.getElementTyp().equals(toCeck.getElementTyp()) && item.getCardType().equals(toCeck.getCardType()) && item.getName().equals(toCeck.getName()) && item.getDamage() == toCeck.getDamage()){
returnval.set(true);
}
});
return returnval.get();
}
/**
* Vergleicht 2 Cards Obj miteinander
* @param toCompare Cards zum vergleichen
* @return True wenn es aus den selben Cards besteht
*/
public boolean equals(Cards toCompare){
AtomicBoolean returnval = new AtomicBoolean(false);
this.cards.forEach(item -> {
if(toCompare.containsCard(item)){
returnval.set(true);
}
});
return returnval.get();
} }
} }

View File

@ -1,21 +1,65 @@
/**
* Alle coins eines Users
*/
public class Coins { public class Coins {
private int amount;
/**
* Erstellt ein neues Münzen Obj
* @param coins Alle münzen des Users
*/
public Coins(int coins) { public Coins(int coins) {
this.amount = coins;
} }
/**
* Holt alle münzen
* @return Alle münzen
*/
public int getCoinAmount() { public int getCoinAmount() {
return 0; return this.amount;
} }
/**
* Fügt münzen hinzu
* @param coins Münzen die hinzugefügt werden -> Positiv
* @throws NegativAmountException Wenn negative münzen hinzugefüght werden
*/
public void addCoin(int coins) throws NegativAmountException{ public void addCoin(int coins) throws NegativAmountException{
throw new NegativAmountException(); if(coins < 0) {
throw new NegativAmountException("Es kann kein negativer amount an Coins hinzugefügt werden");
}else {
this.amount += coins;
}
} }
/**
* Entfernt münzen
* @param coins Münzen die entfernt werden sollen, muss positiv sein
* @return True wenn erfolgreich
* @throws NegativAmountException Wenn ein negativer betrag abgezogen werden soll
*/
public boolean removeCoin(int coins) throws NegativAmountException{ public boolean removeCoin(int coins) throws NegativAmountException{
throw new NegativAmountException(); if(coins < 0) {
throw new NegativAmountException("Es kann kein negativer amount an Coins hinzugefügt werden");
}else {
this.amount -= coins;
return true;
}
} }
public boolean changeCoinAmmount(int coins) { /**
return false; * Ändert den Absoluten Coin amount
* @param coins Neue Coin anzahl, muss positiv sein
* @return true wenn erfolgreich
* @throws NegativAmountException Wenn ein negativer wert eingegeben wird
*/
public boolean changeCoinAmmount(int coins) throws NegativAmountException{
if(coins < 0) {
throw new NegativAmountException("Es kann kein negativer amount an Coins hinzugefügt werden");
}else {
this.amount = coins;
return true;
}
} }
} }

View File

@ -1,2 +1,48 @@
/**
* User Login Daten
*/
public class Credentials { public class Credentials {
private String passwort, username;
/**
* Startet einen neuen User mit folgenden Daten
* @param username Diesem Usernamen
* @param passwort Diesem Passwort
*/
public Credentials(String username, String passwort){
this.username = username;
this.passwort = passwort;
}
/**
* Holt das Passwort des users
* @return PW des Users
*/
public String getPasswort() {
return passwort;
}
/**
* Setzt das User Passwort
* @param passwort Neues Passwort
*/
public void setPasswort(String passwort) {
this.passwort = passwort;
}
/**
* Holt den Usernamen des Users
* @return Username
*/
public String getUsername() {
return username;
}
/**
* Setzt einen neuen Usernamen
* @param username Neuer Username
*/
public void setUsername(String username) {
this.username = username;
}
} }

View File

@ -1,2 +1,64 @@
import java.util.ArrayList;
/**
* Stellt die Verbindung zur "Datenbank" her
* Die "Datenbank" sind hier nur beispieldaten.
*/
public class DBConnection { public class DBConnection {
private ArrayList<TradingDeal> tradingDeals;
private ArrayList<Package> packages;
/**
* Erstellt alle Beispieldaten und simuliert somit den
* Verbindungsaufbau zu einer DB
*/
public DBConnection(){
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
User user = new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000));
this.tradingDeals.add(new TradingDeal(user, c1, ElementTyp.FIRE, 10, CardType.SPELL));
this.packages.add(new Package(stack, "Test Package", 100));
}
/**
* Holt alle verfügbaren TradingDeals
* @return Alle Trading Deals
*/
public ArrayList<TradingDeal> getAllTradingDeals(){
return this.tradingDeals;
}
/**
* Holt alle verfügbaren Packages
* @return Alle Packages
*/
public ArrayList<Package> getAllPackages(){
return this.packages;
}
/**
* Fügt einen neuen Tradingdeal zum Store hinzu
* @param tradingDeal Der neue Deal
*/
public void addTradingDeal(TradingDeal tradingDeal){
this.tradingDeals.add(tradingDeal);
}
/**
* Fügt ein neues Package zu dem Store hinzu
* @param packageDeal Das neue Package
*/
public void addPackage(Package packageDeal){
this.packages.add(packageDeal);
}
} }

View File

@ -1,5 +1,5 @@
public enum EffectivnessType { public enum EffectivnessType {
EFFEKTIVE, EFFECTIVE,
NOTEFFEKTIVE, NOTEFFECTIVE,
NOEFFEKT NOEFFECT
} }

View File

@ -1,3 +1,3 @@
public enum ElementTyp { public enum ElementTyp {
WATER, FIRE WATER, FIRE, NORMAL
} }

View File

@ -1,2 +1,15 @@
/**
* Wenn ein negativer wert eingegeben wird aber ein Positiver erwartet wird, dann kann diese Exception geworfen werden
*/
public class NegativAmountException extends Exception { public class NegativAmountException extends Exception {
/**
* Aufruf des Constructors der Super class Exception
* @param message Fehler Nachrichgt
* @param cause Fehler Ursache
*/
public NegativAmountException(String message){
super(message);
}
} }

View File

@ -1,17 +1,43 @@
/**
* Package besteht aus 4 Karten. Ist eine Erweiterung der Cards, zeigt für 4 Cards den Preis und einen Packagenamen an
*/
public class Package extends Cards{ public class Package extends Cards{
public Package(Cards stack, Cards deck, String name, int price) { private String name;
private int price;
/**
* Erstellt ein neues Package mit den gegebenen Stats
* @param stack Cards des Packages
* @param name Name des Packages
* @param price Price des Packages
*/
public Package(Cards stack, String name, int price) {
super(stack.getCards());
this.name = name;
this.price = price;
} }
/**
* Holt den namen des Packages
* @return Name des Packages
*/
public String getName() { public String getName() {
return null; return this.name;
} }
/**
* Holt den Preis des Packages
* @return Preis des Packages
*/
public int getPrice() { public int getPrice() {
return 0; return this.price;
} }
/**
* Setzt den Namen des Packages
* @param neuName Neuer name des Packages
*/
public void setName(String neuName) { public void setName(String neuName) {
this.name = neuName;
} }
} }

View File

@ -1,17 +1,48 @@
/**
* Erweitert Cards insofern, dass es im Stack auch ein Deck gibt
*/
public class Stack extends Cards{ public class Stack extends Cards{
public Stack(Cards cards, Cards nochNewCards) { private Cards deck;
/**
* Erstellt einen neuen Stack aus den User Cards und seinem Deck
* @param cards Alle Cards des Users
* @param deck Sein Deck
*/
public Stack(Cards cards, Cards deck) {
super(cards.getCards());
this.deck = deck;
} }
/**
* Fügt ein neues Deck in den Stack ein
* @param newCards Gesamtes Deck
*/
public void addDeck(Cards newCards) { public void addDeck(Cards newCards) {
this.deck = newCards;
} }
/**
* Holt das gesamte Deck
* @return Gesamtes Deck
*/
public Cards getDeck() { public Cards getDeck() {
return null; return this.deck;
} }
public boolean delDeck(Cards delCards) { /**
return false; * Löscht eine Card aus dem Deck
* @param toDel Card zum löschen
*/
public void delDeck(Card toDel) {
this.deck.delCard(toDel);
}
/**
* Fügt dem deck eine neue Card ein
* @param toAdd Neue Card
*/
public void addDeckCard(Card toAdd){
this.deck.addCard(toAdd);
} }
} }

View File

@ -9,7 +9,5 @@ public interface Store {
boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2); boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2);
ArrayList<TradingDeal> getPossibleTradingDeals(); ArrayList<TradingDeal> getPossibleTradingDeals(Card toTrade);
ArrayList<TradingDeal> getPossibleAvailableTradingDeals();
} }

View File

@ -1,43 +1,128 @@
/**
* Ein einzelner Trading deal wird hier verwaltet.
*/
public class TradingDeal { public class TradingDeal {
private User tradingUser;
private Card cardToTrade;
private ElementTyp requiredElementType;
private double requiredMinDamage;
private CardType requiredCardType;
/**
* Ein TradingDeal wird erstellt
* @param user User des Deals
* @param cardToTrade Card die getauscht werden soll
* @param requiredElementType Req ElementType für den Tausch
* @param requiredMinDamage Req min damage für den Tausch
* @param requiredCardType Req Card Type für den Tausch
*/
public TradingDeal(User user, Card cardToTrade, ElementTyp requiredElementType, double requiredMinDamage, CardType requiredCardType) { public TradingDeal(User user, Card cardToTrade, ElementTyp requiredElementType, double requiredMinDamage, CardType requiredCardType) {
this.tradingUser = user;
this.cardToTrade = cardToTrade;
this.requiredElementType = requiredElementType;
this.requiredMinDamage = requiredMinDamage;
this.requiredCardType = requiredCardType;
} }
/**
* Holt den Trading User
* @return User der den Trade erstellt hat
*/
public User getTradingUser() { public User getTradingUser() {
return null; return this.tradingUser;
} }
/**
* Card die getraded werden soll
* @return Card die getradet werden soll
*/
public Card getCardToTrade() { public Card getCardToTrade() {
return null; return this.cardToTrade;
} }
/**
* Req Element type holen
* @return Req Element Type
*/
public ElementTyp getRequiredElementType() { public ElementTyp getRequiredElementType() {
return null; return this.requiredElementType;
} }
public int getRequiredMinDamage() { /**
return 0; * Req min damage holen
* @return Req min damage
*/
public double getRequiredMinDamage() {
return this.requiredMinDamage;
} }
/**
* Hole req cardtype
* @return Req CardType
*/
public CardType getRequiredCardType() { public CardType getRequiredCardType() {
return null; return this.requiredCardType;
} }
public void setTradingUser(User user) { /**
* Setzt den User des Trades
* @param tradingUser User der Traded
*/
public void setTradingUser(User tradingUser) {
this.tradingUser = tradingUser;
} }
public void setCardToTrade(Card card) { /**
* Setzt die Karte die Getradet werden soll
* @param cardToTrade Card zum tauschen
*/
public void setCardToTrade(Card cardToTrade) {
this.cardToTrade = cardToTrade;
} }
public void setRequiredElementType(ElementTyp elementTyp) { /**
* Setzt req elementType
* @param requiredElementType Der Req elementType
*/
public void setRequiredElementType(ElementTyp requiredElementType) {
this.requiredElementType = requiredElementType;
} }
public void setRequiredMinDamage(int damage) { /**
* Setzt die req Min damage
* @param requiredMinDamage Die req min gamage
*/
public void setRequiredMinDamage(double requiredMinDamage) {
this.requiredMinDamage = requiredMinDamage;
} }
public void setRequiredCardType(CardType cardType) { /**
* Setzt req cardType
* @param requiredCardType Der Req CardType
*/
public void setRequiredCardType(CardType requiredCardType) {
this.requiredCardType = requiredCardType;
}
/**
* Vom deal im Parameter wird die Card mit den Requirements von THIS verglichen
* @param checkDeal Von diesem Deal wird die CardToTrade geprüft
* @return True wenn der Deal passt
*/
public boolean dealOk(TradingDeal checkDeal){
return this.cardOk(checkDeal.getCardToTrade());
}
/**
* Von der Card im Parameter wird die Card mit den Requirements von THIS verglichen
* @param checkCard Card die mit dem Deal verglichen wird
* @return True wenn der Deal passt
*/
public boolean cardOk(Card checkCard){
if(checkCard.getCardType().equals(this.requiredCardType) && checkCard.getElementTyp().equals(this.requiredElementType) && checkCard.getDamage() >= this.requiredMinDamage){
return true;
}else {
return false;
}
} }
} }

View File

@ -1,55 +1,218 @@
import java.util.ArrayList; import java.util.ArrayList;
/**
* User & Store Logik
*/
public class User implements Store{ public class User implements Store{
private String name, nachname, email;
private Stack stack;
private DBConnection db;
private Credentials credentials;
private Coins coins;
/**
* Erstellt einen neuen User
* @param credentials Zugangsdaten des Users
* @param name Name des Users
* @param nachname Nachname des Users
* @param email Email des Users
* @param stack Alle Karten des Users
* @param coins Alle Münzen des Users
*/
public User(Credentials credentials, String name, String nachname, String email, Stack stack, Coins coins) { public User(Credentials credentials, String name, String nachname, String email, Stack stack, Coins coins) {
this.credentials = credentials;
this.name = name;
this.nachname = nachname;
this.email = email;
this.stack = stack;
this.coins = coins;
this.db = new DBConnection();
} }
/**
* Holt den Stack des Users
* @return Stack des Users
*/
public Stack getStack() {
return stack;
}
/**
* Setzt den Stack eines Users
* @param stack Der neue Stack des Users
*/
public void setStack(Stack stack) {
this.stack = stack;
}
/**
* Holt das DB Obj
* @return Das DB Obj
*/
public DBConnection getDb() {
return db;
}
/**
* Setzt ein neues DB Obj
* @param db Das neue DB Obj
*/
public void setDb(DBConnection db) {
this.db = db;
}
/**
* Holt die eindeutigen Logindaten des Users
* @return Eindeutige Logindaten
*/
public Credentials getCredentials() {
return credentials;
}
/**
* Setzt die eindeutigen Logindaten
* @param credentials Die neuen Credentials des Users
*/
public void setCredentials(Credentials credentials) {
this.credentials = credentials;
}
/**
* Holt alle Coins des Users
* @return Coins des Users
*/
public Coins getCoins() {
return coins;
}
/**
* Setzt alle Coins des Users
* @param coins Neue Coins des Users
*/
public void setCoins(Coins coins) {
this.coins = coins;
}
/**
* Get Name of User
* @return Name of User
*/
public String getName() { public String getName() {
return null; return this.name;
} }
/**
* Get Nachname of User
* @return Nachname of User
*/
public String getNachname() { public String getNachname() {
return null; return this.nachname;
} }
/**
* Email of User
* @return Email of User
*/
public String getEmail() { public String getEmail() {
return null; return this.email;
} }
public String setName(String name) { /**
return null; * Setzt den Namen des Users
* @param name Neuer Name des Users
*/
public void setName(String name) {
this.name = name;
} }
public String setNachname(String nachname) { /**
return null; * Setzt den Nachnamen
* @param nachname Neuer Nachname
*/
public void setNachname(String nachname) {
this.nachname = nachname;
} }
public String setEmail(String email) { /**
return null; * Setzt die Email des Users
* @param email Neue Email des Users
*/
public void setEmail(String email) {
this.email = email;
} }
public Cards buyPackage(Package mypackage) { //Store Methoden
return null;
/**
* Kauft ein Package
* @param mypackage Package welches gekauft werden soll
* @return Alle Karten des neuen Package
* @throws NegativAmountException Wenn ein negativer Preis im Package gesetzt wird.
*/
public ArrayList<Card> buyPackage(Package mypackage) throws NegativAmountException {
ArrayList<Package> availablePackages = db.getAllPackages();
availablePackages.removeIf(obj -> obj.equals(mypackage));
this.coins.removeCoin(mypackage.getPrice());
return mypackage.getCards();
} }
/**
* Fügt dem Store einen neuen Tradingdeal hinzu
* @param tradingDeal Der neue Tradingdeal
*/
public void addTradingDeal(TradingDeal tradingDeal) { public void addTradingDeal(TradingDeal tradingDeal) {
db.addTradingDeal(tradingDeal);
} }
/**
* Holt alle verfügbaren Tradingdeals
* @return Alle verfügbaren Deals
*/
public ArrayList<TradingDeal> getTradingDeals() { public ArrayList<TradingDeal> getTradingDeals() {
return null; return db.getAllTradingDeals();
} }
public boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2) { /**
* Startet ein Trading zw 2 TradingDeals
* @param myTradingDeal Wenn der Deal passt, wird diese Karte aus dem Stack entfernt
* @param storeTradingDeal Wenn der Deal passt, wird diese Karte dem Stack hinzugefügt
* @return True wenn erfolgreich, False wenn die Deals nicht zusammenpassen
*/
public boolean doTrading(TradingDeal myTradingDeal, TradingDeal storeTradingDeal) {
if (storeTradingDeal.dealOk(myTradingDeal)){
stack.delCard(myTradingDeal.getCardToTrade());
stack.addCard(storeTradingDeal.getCardToTrade());
}
return false; return false;
} }
public ArrayList<TradingDeal> getPossibleTradingDeals() { /**
return null; * Gibt alle Möglichen Trading Deals zurück
* @param toTrade Prüft nach diesem Deal
* @return
*/
@Override
public ArrayList<TradingDeal> getPossibleTradingDeals(Card toTrade) {
ArrayList<TradingDeal> storeList = db.getAllTradingDeals();
ArrayList<TradingDeal> possible = new ArrayList<TradingDeal>();
storeList.forEach(item -> {
if(item.cardOk(toTrade)){
possible.add(item);
}
});
return possible;
} }
public ArrayList<TradingDeal> getPossibleAvailableTradingDeals() { /**
return null; * Checkt ob es sich um den selben User handelt
* @param toCheck Mit diesem User wird verglichen
* @return True wenn es der selbe User ist
*/
public boolean equals(User toCheck){
if (toCheck.getCredentials().getUsername() == this.credentials.getUsername() && toCheck.getCredentials().getPasswort() == this.credentials.getPasswort()){
return true;
}else {
return false;
}
} }
} }

View File

@ -7,47 +7,48 @@ public class CardTest {
@Test @Test
public void test_getName() { public void test_getName() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
assertTrue(card.getName() != ""); assertTrue(card.getName().equals("Name"));
} }
@Test @Test
public void test_getDamage() { public void test_getDamage() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
assertTrue(card.getDamage() >= 0); assertTrue(card.getDamage() == 10);
} }
@Test @Test
public void test_getElementType() { public void test_getElementType() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
ElementTyp elementTyp = card.getElementTyp(); ElementTyp elementTyp = card.getElementTyp();
assertTrue(elementTyp != null); assertTrue(elementTyp != ElementTyp.WATER);
} }
@Test @Test
public void test_getCardType() { public void test_getCardType() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
CardType cardType = card.getCardType(); CardType cardType = card.getCardType();
assertTrue(cardType != null); assertTrue(cardType != CardType.SPELL);
} }
@Test @Test
public void test_getEffectivenessAgainst() { public void test_getEffectivenessAgainst() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
EffectivnessType effectivnessType = card.getEffectivenessAgainst(); Card card2 = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
assertTrue(effectivnessType != null); EffectivnessType effectivnessType = card.getEffectivenessAgainst(card2);
assertTrue(effectivnessType != EffectivnessType.NOEFFECT);
} }
@Test @Test
public void test_setName() { public void test_setName() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
boolean result = card.setName("NeuerName"); card.setName("NeuerName");
assertTrue(result); assertTrue(card.getName().equals("NeuerName"));
} }
@Test @Test
public void test_setDamage() { public void test_setDamage() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
boolean result = card.setDamage(100); card.setDamage(100);
assertTrue(result); assertTrue(card.getDamage() == 100);
} }
@Test @Test
public void test_setElementTyp() { public void test_setElementTyp() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL); Card card = new Card("Name", 10, ElementTyp.WATER, CardType.SPELL);
boolean result = card.setElementType(ElementTyp.WATER); card.setElementType(ElementTyp.FIRE);
assertTrue(result); assertTrue(card.getElementTyp() == ElementTyp.FIRE);
} }
} }

View File

@ -5,34 +5,40 @@ import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class CardsTest { public class CardsTest {
public Card newCard, card; private Cards newCards, cards, nochNewCards;
public Cards cards; private Card newCard, card;
public ArrayList<Card> cardsArrayList; private ArrayList<Card> cardsArrayList, cardsArrayList2, cardsArrayList3;
private Stack stack;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL); newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL);
cardsArrayList = new ArrayList<Card>(); cardsArrayList = new ArrayList<Card>();
cardsArrayList2 = new ArrayList<Card>();
cardsArrayList3 = new ArrayList<Card>();
cardsArrayList.add(card); cardsArrayList.add(card);
cardsArrayList2.add(newCard);
cardsArrayList2.add(card);
cards = new Cards(cardsArrayList); cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3);
stack = new Stack(cards, nochNewCards);
} }
@Test @Test
void test_addCard() { void test_addCard() {
ArrayList<Card> result = cards.getCards();
cards.addCard(newCard); cards.addCard(newCard);
cardsArrayList.add(newCard); assertTrue(cards.getCards().equals(cardsArrayList2));
assertTrue(result == cardsArrayList);
} }
@Test @Test
void test_delCard() { void test_delCard() {
boolean result = cards.delCard(newCard); cards.addCard(newCard);
assertTrue(result); cards.delCard(newCard);
assertTrue(cards.getCards().equals(cardsArrayList));
} }
@Test @Test
void test_getCards() { void test_getCards() {
ArrayList<Card> result = cards.getCards(); assertTrue(cards.getCards().equals(cardsArrayList));
assertTrue(result == cardsArrayList);
} }
} }

View File

@ -19,7 +19,7 @@ public class CoinsTest {
coin.addCoin(-10); coin.addCoin(-10);
fail("Erwartet NegativAmountException - addCoin"); fail("Erwartet NegativAmountException - addCoin");
}catch (NegativAmountException negativAmountException) { }catch (NegativAmountException negativAmountException) {
assertTrue(negativAmountException.getMessage()=="negativAmountException"); assertTrue(negativAmountException.getMessage().equals("Es kann kein negativer amount an Coins hinzugefügt werden"));
} }
} }
@ -30,7 +30,7 @@ public class CoinsTest {
coin.removeCoin(-10); coin.removeCoin(-10);
fail("Erwartet NegativAmountException - removeCoin"); fail("Erwartet NegativAmountException - removeCoin");
}catch (NegativAmountException negativAmountException) { }catch (NegativAmountException negativAmountException) {
assertTrue(negativAmountException.getMessage()=="negativAmountException"); assertTrue(negativAmountException.getMessage().equals("Es kann kein negativer amount an Coins hinzugefügt werden"));
} }
} }
@ -47,12 +47,20 @@ public class CoinsTest {
@Test @Test
public void test_changeCoinAmount_true(){ public void test_changeCoinAmount_true(){
Coins coin = new Coins(10); Coins coin = new Coins(10);
assertTrue(coin.changeCoinAmmount(-10)); try {
assertTrue(coin.changeCoinAmmount(10));
} catch (NegativAmountException e) {
e.printStackTrace();
}
} }
@Test @Test
public void test_changeCoinAmount_false(){ public void test_changeCoinAmount_false(){
Coins coin = new Coins(9); Coins coin = new Coins(9);
assertFalse(coin.changeCoinAmmount(-10)); try {
assertTrue(coin.changeCoinAmmount(7));
} catch (NegativAmountException e) {
e.printStackTrace();
}
} }
} }

View File

@ -23,13 +23,13 @@ public class PackageTest {
cards = new Cards(cardsArrayList); cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2); newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3); nochNewCards = new Cards(cardsArrayList3);
myPackage = new Package(cards, nochNewCards, "Name", 100); myPackage = new Package(cards,"Name", 100);
} }
@Test @Test
void test_getName() { void test_getName() {
String result = myPackage.getName(); String result = myPackage.getName();
assertTrue(result=="Name"); assertTrue(result.equals("Name"));
} }
@Test @Test
@ -42,6 +42,6 @@ public class PackageTest {
void test_setName() { void test_setName() {
myPackage.setName("neuName"); myPackage.setName("neuName");
String result = myPackage.getName(); String result = myPackage.getName();
assertTrue(result=="neuName"); assertTrue(result.equals("neuName"));
} }
} }

View File

@ -1,18 +0,0 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.mock;
public class SimpleCardTest {
@Test
@DisplayName("Test - getName()")
public void test_getName(){
//arrange
Card mockedA = mock(Card.class); //Erstellt einen Mock
String name = "Neuer Name";
//act
//assert
}
}

View File

@ -11,6 +11,7 @@ public class StackTest {
private Card newCard, card; private Card newCard, card;
private ArrayList<Card> cardsArrayList, cardsArrayList2, cardsArrayList3; private ArrayList<Card> cardsArrayList, cardsArrayList2, cardsArrayList3;
private Stack stack; private Stack stack;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER); card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
@ -20,6 +21,7 @@ public class StackTest {
cardsArrayList3 = new ArrayList<Card>(); cardsArrayList3 = new ArrayList<Card>();
cardsArrayList.add(card); cardsArrayList.add(card);
cardsArrayList2.add(newCard); cardsArrayList2.add(newCard);
cardsArrayList2.add(card);
cards = new Cards(cardsArrayList); cards = new Cards(cardsArrayList);
newCards = new Cards(cardsArrayList2); newCards = new Cards(cardsArrayList2);
nochNewCards = new Cards(cardsArrayList3); nochNewCards = new Cards(cardsArrayList3);
@ -29,16 +31,17 @@ public class StackTest {
void test_addDeck() { void test_addDeck() {
stack.addDeck(newCards); stack.addDeck(newCards);
Cards result = stack.getDeck(); Cards result = stack.getDeck();
assertTrue(result == newCards); assertTrue(result.equals(newCards));
} }
@Test @Test
void test_delDeck() { void test_delDeck() {
boolean result = stack.delDeck(cards); stack.addDeck(newCards);
assertTrue(result); stack.delDeck(newCard);
assertTrue(stack.getDeck().equals(cards));
} }
@Test @Test
void test_getDeck() { void test_getDeck() {
Cards result = stack.getDeck(); Cards result = stack.getDeck();
assertTrue(result == cards); assertTrue(result.equals(cards));
} }
} }

View File

@ -33,7 +33,7 @@ public class StoreTest {
//Coins //Coins
Coins coins = new Coins(10); Coins coins = new Coins(10);
//User //User
Credentials credentials = new Credentials(); Credentials credentials = new Credentials("username", "passwort");
user = new User(credentials, "name", "nachname", "email", stack, coins); user = new User(credentials, "name", "nachname", "email", stack, coins);
userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins); userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins);
@ -51,32 +51,70 @@ public class StoreTest {
user.addTradingDeal(tradingDeal); user.addTradingDeal(tradingDeal);
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>(); ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
expected.add(tradingDeal); expected.add(tradingDeal);
assertTrue(user.getTradingDeals() == expected); Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
assertTrue(user.getTradingDeals().equals(expected));
} }
@Test @Test
void test_doTrade() { void test_doTrade() {
boolean result = user.doTrading(tradingDeal, tradingDeal); Card cardtest = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
TradingDeal tradingDealtest = new TradingDeal(user, cardtest, ElementTyp.WATER, 100, CardType.MONSTER);
boolean result = user.doTrading(tradingDeal, tradingDealtest);
assertTrue(result); assertTrue(result);
} }
@Test @Test
void test_getTradingDeals() { void test_getTradingDeals() {
ArrayList<TradingDeal> result = user.getTradingDeals(); ArrayList<TradingDeal> result = user.getTradingDeals();
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>(); ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
Cards deck = new Cards();
Cards stack = new Cards();
deck.addCard(c1);
deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
expected.add(tradingDeal); expected.add(tradingDeal);
assertTrue(result == expected); assertTrue(result.equals(expected));
} }
@Test @Test
void test_getPossibleTradingDeals() { void test_getPossibleTradingDeals() {
ArrayList<TradingDeal> result = user.getPossibleTradingDeals(); Card testCard = new Card("Test", 15, ElementTyp.FIRE, CardType.SPELL);
ArrayList<TradingDeal> result = user.getPossibleTradingDeals(testCard);
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>(); ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>();
expected.add(tradingDeal); Card c1 = new Card("Name", 10, ElementTyp.FIRE, CardType.MONSTER);
assertTrue(result == expected); Card c2 = new Card("Name1", 12, ElementTyp.FIRE, CardType.SPELL);
} Card c3 = new Card("Name2", 13, ElementTyp.WATER, CardType.MONSTER);
@Test Card c4 = new Card("Name3", 14, ElementTyp.WATER, CardType.SPELL);
void test_getAvailableTradingDeals() { Card c5 = new Card("Name4", 15, ElementTyp.FIRE, CardType.MONSTER);
ArrayList<TradingDeal> result = user.getPossibleAvailableTradingDeals(); Cards deck = new Cards();
ArrayList<TradingDeal> expected = new ArrayList<TradingDeal>(); Cards stack = new Cards();
expected.add(tradingDeal); deck.addCard(c1);
assertTrue(result == expected); deck.addCard(c2);
stack.addCard(c3);
stack.addCard(c4);
stack.addCard(c5);
TradingDeal vonDB = new TradingDeal(new User(new Credentials("username", "passwort"), "Name", "Nachname", "Email", new Stack(stack, deck), new Coins(1000)), c1, ElementTyp.FIRE, 10, CardType.SPELL);
expected.add(vonDB);
assertTrue(result.equals(expected));
} }
} }

View File

@ -33,9 +33,10 @@ public class TradingDealTest {
//Coins //Coins
Coins coins = new Coins(10); Coins coins = new Coins(10);
//User //User
Credentials credentials = new Credentials(); Credentials credentials = new Credentials("username", "passwort");
Credentials newCredentials = new Credentials("usernamenew", "passwortnew");
user = new User(credentials, "name", "nachname", "email", stack, coins); user = new User(credentials, "name", "nachname", "email", stack, coins);
userNew = new User(credentials, "nameNew", "nachnameNew", "emailNew", stack, coins); userNew = new User(newCredentials, "nameNew", "nachnameNew", "emailNew", stack, coins);
//Trading Deal //Trading Deal
Card cardToTrade = card; Card cardToTrade = card;
@ -48,12 +49,12 @@ public class TradingDealTest {
@Test @Test
void test_getTradingUser() { void test_getTradingUser() {
User result = tradingDeal.getTradingUser(); User result = tradingDeal.getTradingUser();
assertTrue(result==user); assertTrue(result.equals(user));
} }
@Test @Test
void test_getCardToTrade() { void test_getCardToTrade() {
Card result = tradingDeal.getCardToTrade(); Card result = tradingDeal.getCardToTrade();
assertTrue(result==card); assertTrue(result.equals(card));
} }
@Test @Test
void test_getRequiredElementType() { void test_getRequiredElementType() {
@ -62,7 +63,7 @@ public class TradingDealTest {
} }
@Test @Test
void test_getRequiredMinDamage() { void test_getRequiredMinDamage() {
int result = tradingDeal.getRequiredMinDamage(); double result = tradingDeal.getRequiredMinDamage();
assertTrue(result==100); assertTrue(result==100);
} }
@Test @Test
@ -75,7 +76,7 @@ public class TradingDealTest {
void test_setTradingUser() { void test_setTradingUser() {
tradingDeal.setTradingUser(userNew); tradingDeal.setTradingUser(userNew);
User result = tradingDeal.getTradingUser(); User result = tradingDeal.getTradingUser();
assertTrue(result==userNew); assertTrue(result.equals(userNew));
} }
@Test @Test
void test_setCardToTrade() { void test_setCardToTrade() {
@ -92,7 +93,7 @@ public class TradingDealTest {
@Test @Test
void test_setRequiredMinDamage() { void test_setRequiredMinDamage() {
tradingDeal.setRequiredMinDamage(10); tradingDeal.setRequiredMinDamage(10);
int result = tradingDeal.getRequiredMinDamage(); double result = tradingDeal.getRequiredMinDamage();
assertTrue(result==10); assertTrue(result==10);
} }
@Test @Test

View File

@ -30,51 +30,59 @@ public class UserTest {
nochNewCards = new Cards(cardsArrayList3); nochNewCards = new Cards(cardsArrayList3);
stack = new Stack(cards, nochNewCards); stack = new Stack(cards, nochNewCards);
//Package //Package
myPackage = new Package(cards, nochNewCards, "Name", 100); myPackage = new Package(cards, "Name", 100);
//Coins //Coins
Coins coins = new Coins(10); Coins coins = new Coins(10);
//User //User
Credentials credentials = new Credentials(); Credentials credentials = new Credentials("username", "pw");
user = new User(credentials, "name", "nachname", "email", stack, coins); user = new User(credentials, "name", "nachname", "email", stack, coins);
} }
@Test @Test
public void test_getName() { public void test_getName() {
String result = user.getName(); String result = user.getName();
assertTrue(result != ""); assertTrue(result != "name");
} }
@Test @Test
public void test_getNachname() { public void test_getNachname() {
String result = user.getNachname(); String result = user.getNachname();
assertTrue(result != ""); assertTrue(result != "nachname");
} }
@Test @Test
public void test_getEmail() { public void test_getEmail() {
String result = user.getEmail(); String result = user.getEmail();
assertTrue(result != ""); assertTrue(result != "email");
} }
@Test @Test
public void test_setName() { public void test_setName() {
String newstring = "new"; String newstring = "new";
String result = user.setName(newstring); user.setName(newstring);
String result = user.getName();
assertTrue(result != newstring); assertTrue(result != newstring);
} }
@Test @Test
public void test_setNachname() { public void test_setNachname() {
String newstring = "new"; String newstring = "new";
String result = user.setNachname(newstring); user.setNachname(newstring);
String result = user.getNachname();
assertTrue(result != newstring); assertTrue(result != newstring);
} }
@Test @Test
public void test_setEmail() { public void test_setEmail() {
String newstring = "new"; String newstring = "new";
String result = user.setEmail(newstring); user.setEmail(newstring);
String result = user.getEmail();
assertTrue(result != newstring); assertTrue(result != newstring);
} }
@Test @Test
public void test_buyPackage(){ public void test_buyPackage(){
Cards cards = user.buyPackage(myPackage); Cards cards = null;
assertTrue(cards != null); try {
cards = new Cards(user.buyPackage(myPackage));
} catch (NegativAmountException e) {
e.printStackTrace();
}
assertTrue(cards.equals(new Cards(myPackage.getCards())));
} }
} }