Bug fixes + removed unused + removed Warnings + Bugfix JavaDoc

This commit is contained in:
Georg Reisinger 2021-01-02 17:21:27 +01:00
parent 012b8bb532
commit 3d67d2ad16
14 changed files with 275 additions and 355 deletions

View File

@ -1,2 +1,60 @@
# SWE1-MTCG
Monster Trading at.reisinger.obj.Card Game
# Monster Trading Card Game
Created by *Georg Reisinger*
## Protocol
* RestServer von https://github.com/DerGeorg/RESTServer
* MTCG Git Repo https://github.com/DerGeorg/SWE1-MTCG
* JavaDoc online auf: http://mtcg.dergeorg.at
* Postgres Server läuft auf einem Raspberry Pi 4 --> http://postgres.dergeorg.at
* User Table
* *Alle User die in MTCG registriert sind*
* User_cards Table
* *Alle Cards der User*
* User_deck Table
* *Deck der User*
* Battle Table
* *Battle Einladungen*
* Battle_log Table
* *Nach beendetem battle wird hier das Log gespeichert*
* Package Table
* *Alle Packages die die User bekommen können*
* Card Table
* *Alle Cards die in dem Spiel verwendet werden*
* *Typ der Card wird automatisch in Card und Element Typ getrennt*
* Trading Table
* *Alle aktiven Trading deals*
## API Beschreibung
### GET
| ROUTE | BESCHREIBUNG | ATTRIBUTE | RETURN | HEADER |
|--------------------|------------------------------------|-----------|-------------------------|------------------------------------------------------|
| /cards | show all acquired cards | / | Cards Object | --header "Authorization: Basic kienboec-mtcgToken" |
| /deck | show deck | / | Cards Object | --header "Authorization: Basic kienboec-mtcgToken" |
| /deck?format=plain | show deck different representation | / | Card names Array | --header "Authorization: Basic kienboec-mtcgToken" |
| /users/{username} | get user | / | User Object | --header "Authorization: Basic kienboec-mtcgToken" |
| /stats | get stats about all battles | / | All battle Logs | --header "Authorization: Basic kienboec-mtcgToken" |
| /score | get score, about last battle | / | Last Battle Log | --header "Authorization: Basic kienboec-mtcgToken" |
| /tradings | get trading deals | / | List TradingDeal Object | --header "Authorization: Basic kienboec-mtcgToken" |
### POST
| ROUTE | BESCHREIBUNG | ATTRIBUTE | RETURN | HEADER |
|------------------------|---------------------------|--------------------------------------|---------------------|------------------------------------------------------|
| /users | create user | Username, Password | User Object | / |
| /sessions | login user | Username, Password | login token | / |
| /packages | create package | [ID, Name, Damage]x5 | Package Object | --header "Authorization: Basic admin-mtcgToken" |
| /transactions/packages | acquire packages kienboec | / | Package Object | --header "Authorization: Basic kienboec-mtcgToken" |
| /battles | Battle | / | Anweisungen String | --header "Authorization: Basic kienboec-mtcgToken" |
| /tradings | create tradingdeal | Id, CardToTrade, Type, MinimumDamage | TradingDeal Object | --header "Authorization: Basic kienboec-mtcgToken" |
| /tradings/{TradeID} | Do Trade | CardID | New Card Object | --header "Authorization: Basic kienboec-mtcgToken" |
### PUT
| ROUTE | BESCHREIBUNG | ATTRIBUTE | RETURN | HEADER |
|-------------------|----------------|------------------|--------------|------------------------------------------------------|
| /deck | configure deck | [ID, ID, ID, ID] | Cards Object | --header "Authorization: Basic kienboec-mtcgToken" |
| /users/{username} | / | Name, Bio, Image | User Object | --header "Authorization: Basic kienboec-mtcgToken" |
### DELETE
| ROUTE | BESCHREIBUNG | ATTRIBUTE | RETURN | HEADER |
|---------------------|---------------------|-----------|--------|------------------------------------------------------|
| /tradings/{TradeID} | delete trading deal | / | / | --header "Authorization: Basic kienboec-mtcgToken" |
## Zeit
5 Tage x 6 Stunden = 30 Stunden

View File

@ -16,7 +16,7 @@ public class Battle {
private final Cards deckPlayer1Init;
private Cards deckPlayer2Init;
private final ArrayList<String> log = new ArrayList<>();
private ArrayList<Card> d1 = new ArrayList<>(), d2 = new ArrayList<>();
/**
* Erstellt ein neues Battle, im zustand offenes battle
@ -44,32 +44,32 @@ public class Battle {
if(deckPlayer1.getCards().size() == 4 && deckPlayer2.getCards().size() == 4) {
//SHUFFLE DECK
ArrayList<Card> d1 = deckPlayer1.getCards();
ArrayList<Card> d2 = deckPlayer2.getCards();
Collections.shuffle(d1);
Collections.shuffle(d2);
deckPlayer1.setCards(d1);
deckPlayer1.setCards(d2);
this.d1 = deckPlayer1.getCards();
this.d2 = deckPlayer2.getCards();
Collections.shuffle(this.d1);
Collections.shuffle(this.d2);
deckPlayer1.setCards(this.d1);
deckPlayer1.setCards(this.d2);
//Runden
int maxroundcount = 100, counter = 0, counter2 = 0;
while(counter<maxroundcount) {
counter++;
counter2++;
if(counter2 < d1.size()-1 || counter2 < d2.size()-1){
if(counter2 < this.d1.size()-1 || counter2 < this.d2.size()-1){
counter2 = 0;
}
if (d1.size() > 0 && d2.size() > 0 && counter<=maxroundcount) {
if (this.d1.size() > 0 && this.d2.size() > 0 && counter<=maxroundcount) {
System.out.println("Runde: " + counter);
System.out.println("deck 1 size: " + d1.size() + " Deck 2 size: " + d2.size() + " counter2: " + counter2);
Card c1 = d1.get(counter2);
Card c2 = d2.get(counter2);
System.out.println("deck 1 size: " + this.d1.size() + " Deck 2 size: " + this.d2.size() + " counter2: " + counter2);
Card c1 = this.d1.get(counter2);
Card c2 = this.d2.get(counter2);
System.out.println("Card 1: " + c1.getElementTyp() + c1.getCardType() + "\nCard 2: " + c2.getElementTyp() + c2.getCardType());
//GLEICHER TYP Monster
if (!c1.getCardType().name().equalsIgnoreCase("SPELL") && !c2.getCardType().name().equalsIgnoreCase("SPELL")) {
System.out.println("Same Monster");
//Check ob eine der beiden Carten ein Dragon ist
if ((c1.getCardType().name().equalsIgnoreCase("DRANGON") && !c2.getCardType().name().equalsIgnoreCase("DRANGON") || (!c1.getCardType().name().equalsIgnoreCase("DRANGON") && c2.getCardType().name().equalsIgnoreCase("DRANGON")))) {
if ((c1.getCardType().name().equalsIgnoreCase("DRAGON") && !c2.getCardType().name().equalsIgnoreCase("DRAGON") || (!c1.getCardType().name().equalsIgnoreCase("DRAGON") && c2.getCardType().name().equalsIgnoreCase("DRAGON")))) {
//Eine der Karten is Dragon
System.out.println("Eine ist ein dragon");
Card dragon;
@ -99,17 +99,17 @@ public class Battle {
if (dragon.getDamage() > goblin.getDamage()) {
//Drache ist stärker
if (dragonOwner == 1) {
d1.add(c2);
d2.remove(c2);
this.d1.add(c2);
this.d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
} else {
d2.add(c1);
d1.remove(c1);
this.d2.add(c1);
this.d1.remove(c1);
this.scorePlayer1 -= 5;
this.scorePlayer2 += 3;
}
log.add("Player " + dragonOwner + " gewinnt!\nDrache ist stärker! Drache: " + dragon.getDamage() + " vs Goblin: " + goblin.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
this.log.add("Player " + dragonOwner + " gewinnt!\nDrache ist stärker! Drache: " + dragon.getDamage() + " vs Goblin: " + goblin.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
} else {
System.out.println("DRAW: Drache zu schwach um anzugreifen und GOBLIN zu feige.");
}
@ -126,33 +126,21 @@ public class Battle {
if (fireelf.getDamage() > dragon.getDamage()) {
//Fireelf ist stärker
if (dragonOwner == 1) {
d2.add(c1);
d1.remove(c1);
this.d2.add(c1);
this.d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
} else {
d1.add(c2);
d2.remove(c2);
this.d1.add(c2);
this.d2.remove(c2);
this.scorePlayer2 -= 5;
this.scorePlayer1 += 3;
}
log.add("Player " + dragonOwner + " gewinnt!\nWizzard ist stärker! Drache: " + dragon.getDamage() + " vs FireElves: " + fireelf.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
this.log.add("Player " + dragonOwner + " gewinnt!\nWizzard ist stärker! Drache: " + dragon.getDamage() + " vs FireElves: " + fireelf.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
}
//Sonst nix tun, weil der drache den elf ned angreifen kann
} else {
if (c1.getDamage() > c2.getDamage()) {
d1.add(c2);
d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
} else if (c1.getDamage() < c2.getDamage()) {
d2.add(c1);
d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
}
calculateWinnerMoveCards(c1, c2);
}
//Checkt ob eine der beiden karten ein wizzard ist und der andere ein ork
@ -172,39 +160,27 @@ public class Battle {
}
if (wizzard != null && wizzard.getDamage() > ork.getDamage()) {
if (wizzardOwner == 1) {
d1.add(c2);
d2.remove(c2);
this.d1.add(c2);
this.d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
} else {
d2.add(c1);
d1.remove(c1);
this.d2.add(c1);
this.d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
}
log.add("Player " + wizzardOwner + " gewinnt!\nWizzard ist stärker! Wizzard: " + wizzard.getDamage() + " vs Ork: " + ork.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
this.log.add("Player " + wizzardOwner + " gewinnt!\nWizzard ist stärker! Wizzard: " + wizzard.getDamage() + " vs Ork: " + ork.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
}
//Sonst nix tun, weil der ork dem wizzard keinen schaden machen kann
} else {
//PURE MONSTER
if (c1.getDamage() > c2.getDamage()) {
d1.add(c2);
d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
} else if (c1.getDamage() < c2.getDamage()) {
d2.add(c1);
d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
}
calculateWinnerMoveCards(c1, c2);
//sonst nix weil bei gleichen damage --> draw
}
} else {//PURE SPELL & mixed
double damagePlayer1 = -1, damagePlayer2 = -1;
double damagePlayer1, damagePlayer2;
if (c1.getCardType().name().equalsIgnoreCase("KNIGHT") || c2.getCardType().name().equalsIgnoreCase("KNIGHT")) {
//Mixed mit "Spezialeffekt" KNIGHT
@ -258,167 +234,37 @@ public class Battle {
}
if (damageKnight > damageOther) {
if (knightOwner == 1) {
d1.add(c2);
d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damageKnight + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p1win(c1,c2);
} else {
d2.add(c1);
d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damageKnight + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p2win(c1, c2);
}
} else if (damageKnight < damageOther) {
if (knightOwner == 2) {
d1.add(c2);
d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damageOther + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damageKnight + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p1win(c1, c2);
} else {
d2.add(c1);
d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damageOther + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damageKnight + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p2win(c1, c2);
}
}
} else if (c1.getCardType().name().equalsIgnoreCase("KRAKEN") || c2.getCardType().name().equalsIgnoreCase("KRAKEN")) {
//Mixed mit "Spezialeffekt" KRAKEN
if (c1.getCardType().name().equalsIgnoreCase("KRAKEN")) {
d1.add(c2);
d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + c1.getDamage() + " vs " + c2.getElementTyp() + c2.getCardType() + ": 0\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p1win(c1, c2);
} else if (c2.getCardType().name().equalsIgnoreCase("KRAKEN")) {
d2.add(c1);
d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + c2.getDamage() + " vs " + c1.getElementTyp() + c1.getCardType() + ": 0\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p2win(c1, c2);
}
} else {
////PURE SPELL & mixed mit elementen
System.out.println("Spell und mixed mit elementen");
//Player 1 Damage berechnen
switch (c1.getElementTyp().name().toUpperCase()) {
case "FIRE":
switch (c2.getElementTyp().name().toUpperCase()) {
case "REGULAR":
//effective
damagePlayer1 = c1.getDamage() * 2;
break;
case "WATER":
//not effective
damagePlayer1 = c1.getDamage() / 2;
break;
case "FIRE":
//no effect
damagePlayer1 = c1.getDamage();
break;
}
break;
case "WATER":
switch (c2.getElementTyp().name().toUpperCase()) {
case "FIRE":
//effective
damagePlayer1 = c1.getDamage() * 2;
break;
case "WATER":
//no effect
damagePlayer1 = c1.getDamage();
break;
case "REGULAR":
//not effective
damagePlayer1 = c1.getDamage() / 2;
break;
}
break;
case "REGULAR":
switch (c2.getElementTyp().name().toUpperCase()) {
case "WATER":
//effective
damagePlayer1 = c1.getDamage() * 2;
break;
case "FIRE":
//not effective
damagePlayer1 = c1.getDamage() / 2;
break;
case "REGULAR":
//no effect
damagePlayer1 = c1.getDamage();
break;
}
break;
}
damagePlayer1 = calculateEffectiveness(c1, c2);
//P2 damage
switch (c2.getElementTyp().name().toUpperCase()) {
case "FIRE":
switch (c1.getElementTyp().name().toUpperCase()) {
case "REGULAR":
//effective
damagePlayer2 = c2.getDamage() * 2;
break;
case "WATER":
//not effective
damagePlayer2 = c2.getDamage() / 2;
break;
case "FIRE":
//no effect
damagePlayer2 = c2.getDamage();
break;
}
break;
case "WATER":
switch (c1.getElementTyp().name().toUpperCase()) {
case "FIRE":
//effective
damagePlayer2 = c2.getDamage() * 2;
break;
case "WATER":
//no effect
damagePlayer2 = c2.getDamage();
break;
case "REGULAR":
//not effective
damagePlayer2 = c2.getDamage() / 2;
break;
}
break;
case "REGULAR":
switch (c1.getElementTyp().name().toUpperCase()) {
case "WATER":
//effective
damagePlayer2 = c2.getDamage() * 2;
break;
case "FIRE":
//not effective
damagePlayer2 = c2.getDamage() / 2;
break;
case "REGULAR":
//no effect
damagePlayer2 = c2.getDamage();
break;
}
break;
}
damagePlayer2 = calculateEffectiveness(c2, c1);
if (damagePlayer1 > -1 && damagePlayer2 > -1) {
if (damagePlayer1 > damagePlayer2) {
d1.add(c2);
d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damagePlayer1 + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damagePlayer2 + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p1win(c1, c2);
} else if (damagePlayer2 > damagePlayer1) {
d2.add(c1);
d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damagePlayer2 + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damagePlayer1 + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
p2win(c1, c2);
}
} else {
System.out.println("Damage konnte nicht berechnet werden");
@ -430,8 +276,8 @@ public class Battle {
return true;
}
}
this.deckPlayer1 = new Cards(d1);
this.deckPlayer2 = new Cards(d2);
this.deckPlayer1 = new Cards(this.d1);
this.deckPlayer2 = new Cards(this.d2);
}else{
System.out.println("Einer der Spieler hat zu wenige Karten im Deck");
return false;
@ -439,54 +285,200 @@ public class Battle {
return true;
}
/**
* Aktion wenn Player 1 gewinnt
* @param c1 Card player 1
* @param c2 Card player 2
*/
private void p1win(Card c1, Card c2){
this.d1.add(c2);
this.d2.remove(c2);
this.scorePlayer1 += 3;
this.scorePlayer2 -= 5;
this.log.add("Player 1 gewinnt!\n" + c1.getElementTyp() + c1.getCardType() + " ist stärker! " + c1.getElementTyp() + c1.getCardType() + ": " + damageKnight + " vs " + c2.getElementTyp() + c2.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
}
/**
* Aktion wenn Player 2 gewinnt
* @param c1 Card player 1
* @param c2 Card player 2
*/
private void p2win(Card c1, Card c2){
this.d2.add(c1);
this.d1.remove(c1);
this.scorePlayer2 += 3;
this.scorePlayer1 -= 5;
this.log.add("Player 2 gewinnt!\n" + c2.getElementTyp() + c2.getCardType() + " ist stärker! " + c2.getElementTyp() + c2.getCardType() + ": " + damageKnight + " vs " + c1.getElementTyp() + c1.getCardType() + ": " + damageOther + "\nPlayer 1 score: " + scorePlayer1 + "\nPlayer 2 score: " + scorePlayer2);
}
/**
* Ermittelt den gewinner der Runde, moved die deck cards und setzt den score
* @param c1 Card p1
* @param c2 Card p2
*/
private void calculateWinnerMoveCards(Card c1, Card c2) {
if (c1.getDamage() > c2.getDamage()) {
p1win(c1, c2);
} else if (c1.getDamage() < c2.getDamage()) {
p2win(c1, c2);
}
}
/**
* Berechnet den Damage der Karten
* @param c1 Card von p1
* @param c2 Card von p2
* @return Damage
*/
private double calculateEffectiveness(Card c1, Card c2){
double damagePlayer1 = 0;
switch (c1.getElementTyp().name().toUpperCase()) {
case "FIRE":
switch (c2.getElementTyp().name().toUpperCase()) {
case "REGULAR":
//effective
damagePlayer1 = c1.getDamage() * 2;
break;
case "WATER":
//not effective
damagePlayer1 = c1.getDamage() / 2;
break;
case "FIRE":
//no effect
damagePlayer1 = c1.getDamage();
break;
}
break;
case "WATER":
switch (c2.getElementTyp().name().toUpperCase()) {
case "FIRE":
//effective
damagePlayer1 = c1.getDamage() * 2;
break;
case "WATER":
//no effect
damagePlayer1 = c1.getDamage();
break;
case "REGULAR":
//not effective
damagePlayer1 = c1.getDamage() / 2;
break;
}
break;
case "REGULAR":
switch (c2.getElementTyp().name().toUpperCase()) {
case "WATER":
//effective
damagePlayer1 = c1.getDamage() * 2;
break;
case "FIRE":
//not effective
damagePlayer1 = c1.getDamage() / 2;
break;
case "REGULAR":
//no effect
damagePlayer1 = c1.getDamage();
break;
}
break;
}
return damagePlayer1;
}
/**
* Get the log
* @return Das log als ArrayList
*/
public ArrayList<String> getLog() {
return log;
return this.log;
}
/**
* Get Battle id
* @return battleID
*/
public int getId() {
return id;
}
/**
* Get Player 1 als User
* @return User Obj
*/
public User getPlayer1() {
return player1;
}
/**
* Get Player 2 als User
* @return User Obj
*/
public User getPlayer2() {
return player2;
}
/**
* Set Player 1 als User
* @param player2 User Obj
*/
public void setPlayer2(User player2) {
this.player2 = player2;
}
/**
* Get Score von Player 1
* @return Score von player
*/
public int getScorePlayer1() {
return scorePlayer1;
}
/**
* Get Score von Player 2
* @return Score von player
*/
public int getScorePlayer2() {
return scorePlayer2;
}
/**
* Get Deck Player 1
* @return Deck als Cards von player
*/
public Cards getDeckPlayer1() {
return deckPlayer1;
}
/**
* Get Deck Player 2
* @return Deck als Cards von player
*/
public Cards getDeckPlayer2() {
return deckPlayer2;
}
/**
* Set Deck Player 1
* @param deckPlayer2 Deck als Cards von player
*/
public void setDeckPlayer2(Cards deckPlayer2) {
this.deckPlayer2 = deckPlayer2;
this.deckPlayer2Init = deckPlayer2;
}
/**
* Get starting deck von player 1
* @return Deck wie es zu beginn des Battles war
*/
public Cards getDeckPlayer1Init() {
return deckPlayer1Init;
}
/**
* Get starting deck von player 2
* @return Deck wie es zu beginn des Battles war
*/
public Cards getDeckPlayer2Init() {
return deckPlayer2Init;
}

View File

@ -20,6 +20,7 @@ public class Card {
private ElementTyp elementTyp;
@JsonProperty
private final CardType cardType;
@SuppressWarnings("unused")
@JsonProperty
private boolean locked;
@ -92,15 +93,6 @@ public class Card {
this.cardType = tmpCard;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
/**
* Holt den Namen der at.reisinger.obj.Card
* @return Name der at.reisinger.obj.Card
@ -138,7 +130,7 @@ public class Card {
}
/**
* Setztden namen der at.reisinger.obj.Card
* Setzt den namen der Card
* @param neuerName Name der at.reisinger.obj.Card
*/
@JsonSetter

View File

@ -4,7 +4,7 @@ package at.reisinger.obj;
* Alle coins eines Users
*/
public class Coins {
private int amount;
private final int amount;
/**
* Erstellt ein neues Münzen Obj
@ -21,42 +21,4 @@ public class Coins {
public int getCoinAmount() {
return this.amount;
}
/**
* Fügt münzen hinzu
* @param coins Münzen die hinzugefügt werden -> Positiv
*/
public void addCoin(int coins){
if(coins > 0) {
this.amount += coins;
}
}
/**
* Entfernt münzen
* @param coins Münzen die entfernt werden sollen, muss positiv sein
* @return True wenn erfolgreich
*/
public boolean removeCoin(int coins){
if(coins < 0) {
return false;
}else {
this.amount -= coins;
return true;
}
}
/**
* Ändert den Absoluten Coin amount
* @param coins Neue Coin anzahl, muss positiv sein
* @return true wenn erfolgreich
*/
public boolean changeCoinAmmount(int coins){
if(coins < 0) {
return false;
}else {
this.amount = coins;
return true;
}
}
}

View File

@ -30,6 +30,7 @@ public class TradingDeal {
* @param requiredElementType Req ElementType für den Tausch
* @param requiredMinDamage Req min damage für den Tausch
* @param requiredCardType Req at.reisinger.obj.Card Type für den Tausch
* @param username Username der den Deal erstellt
*/
public TradingDeal(String id, Card cardToTrade, ElementTyp requiredElementType, double requiredMinDamage, CardType requiredCardType, String username) {
this.id = id;
@ -52,6 +53,8 @@ public class TradingDeal {
* @param cardToTrade at.reisinger.obj.Card die getauscht werden soll
* @param type ElementTyp und CardType in einem String. Beide Enums werden durch diesen String gewählt.
* Wird kein passender Typ gefunden, dann bleibt diese Eigenschaft auf null
* @param username Username der den TradingDeal erstellt
* @param requiredMinDamage Required Min Damage
*/
@JsonCreator
public TradingDeal(@JsonProperty("Id") String id, @JsonProperty("CardToTrade") Card cardToTrade, @JsonProperty("MinimumDamage") double requiredMinDamage, @JsonProperty("Type") String type, String username) {

View File

@ -2,52 +2,24 @@ package at.reisinger.obj;
import com.fasterxml.jackson.annotation.*;
import java.util.ArrayList;
/**
* at.reisinger.obj.User & at.reisinger.Store Logik
* User Objekt
*/
@JsonAutoDetect
public class User{
@JsonProperty
private String name, nachname, email, bio, image;
//private DBConnection db;
@JsonProperty
private final Credentials credentials;
@JsonProperty
private final Coins coins;
/*
* Erstellt einen neuen at.reisinger.obj.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
@JsonCreator
public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Stack stack,@JsonProperty Coins coins) {
public User(@JsonProperty Credentials credentials, @JsonProperty String name, @JsonProperty String nachname, @JsonProperty String email, @SuppressWarnings("unused") @JsonProperty Coins coins, @JsonProperty String bio, @JsonProperty String image) {
this.credentials = credentials;
this.name = name;
this.nachname = nachname;
this.email = email;
this.stack = stack;
this.coins = coins;
//this.db = new at.reisinger.server.DBConnection();
}
*/
@JsonCreator
public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Coins coins, @JsonProperty String bio, @JsonProperty String image) {
this.credentials = credentials;
this.name = name;
this.nachname = nachname;
this.email = email;
//this.stack = null;
this.coins = coins;
this.bio = bio;
this.image = image;
//this.db = new at.reisinger.server.DBConnection();
}
/**
@ -149,15 +121,4 @@ public class User{
this.email = email;
}
//at.reisinger.Store Methoden
/**
* Kauft ein at.reisinger.obj.Package
* @param mypackage at.reisinger.obj.Package welches gekauft werden soll
* @return Alle Karten des neuen at.reisinger.obj.Package
*/
public ArrayList<Card> buyPackage(Package mypackage){
this.coins.removeCoin(mypackage.getPrice());
return mypackage.getCards();
}
}

View File

@ -87,6 +87,7 @@ public class DBConnection {
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select max(id) from battle_log where playerone = '" + username + "' or playertwo = '" + username + "';");
//noinspection LoopStatementThatDoesntLoop
while (rs.next()) {
id = rs.getInt("max");
System.out.println("select max(id) from battle_log where playerone = '" + username + "' or playerone = '" + username + "';");
@ -120,6 +121,7 @@ public class DBConnection {
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select * from battle_log where id = " + battleId + ";");
//noinspection LoopStatementThatDoesntLoop
while (rs.next()) {
id = rs.getInt("id");
playerone = rs.getString("playerone");
@ -155,6 +157,7 @@ public class DBConnection {
/**
* Fügt der Battle tabelle ein battle hinzu
* @param usernamecreator Username der das Battle erstellt hat
* @return True bei erfolg, sonst false
*/
public boolean addBattle(String usernamecreator){
@ -187,6 +190,7 @@ public class DBConnection {
try {
stmt = this.c.createStatement();
ResultSet rs = stmt.executeQuery("select * from battle limit 1;");
//noinspection LoopStatementThatDoesntLoop
while (rs.next()) {
battleid = rs.getInt("battleid");
usernamecreator = rs.getString("usernamecreator");
@ -238,6 +242,7 @@ public class DBConnection {
* @param playertwo Name vom Player 2
* @param playeronescore Score vom Player 1
* @param playertwoscore Score vom Player 2
* @param log Log des Battles
* @return true bei erfolg sonst false
*/
public boolean addBattleLog(String id, String playerone, String playertwo, String playeronescore, String playertwoscore, String log){
@ -344,7 +349,7 @@ public class DBConnection {
/**
* Setzt das Deck eines Users
* @param username Username von dem das Deck gesetzt werden soll
* @param deck Die ID´s des Decks in der Form einer ArrayList<String>
* @param deck Die ID´s des Decks in der Form einer ArrayList
* @return True bei erfolg, sonst false
*/
public boolean setDeck(String username, List<String> deck){
@ -539,6 +544,7 @@ public class DBConnection {
* Coins setzten
*
* @param coins Anzahl die zu setzten ist
* @param username Username von dem die Coins geupdated werden sollen
* @return True bei erfolg, sonst false
*/
public boolean updateCoins(int coins, String username) {
@ -547,7 +553,7 @@ public class DBConnection {
/**
* Gibt die Anzahl an verfügbaren coins zurück
*
* @param username Der username von dem die Coins geholt werden sollen
* @return Anzahl der Coins, -1 ist error
*/
public int checkCoins(String username) {
@ -660,6 +666,8 @@ public class DBConnection {
* @param password Passwort des Users
* @param nachname nachname des Users
* @param email Email des Users
* @param bio Bio des Users
* @param image Image des Users
* @return True wenn alles erfolgreich war, false wenn es nicht erfolgreich war
*/
public boolean addUser(String username, String password, String nachname, String email, String bio, String image) {

View File

@ -33,6 +33,7 @@ public class Main {
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(port);
//noinspection InfiniteLoopStatement
while (true){
this.socket = serverSocket.accept();
requestResponding();

View File

@ -30,6 +30,7 @@ public class PostgresHelper {
/**
* Führt ein Sql statement ohne rückgabe aus, mit message nachricht
* @param sql Sql command
* @param message Mesasage die vor dem Durchführen angezeigt wird
* @return True bei erfolg, sonst false
*/
public static boolean executeUpdateMessage(String sql, String message){

View File

@ -24,6 +24,7 @@ public class Request {
/**
* Besorgt alle nötigen infos aus dem request
* @param socket Socket von dem der Request kommt
* @throws IOException Input Output Exception
*/
public Request(Socket socket) throws IOException {
StringBuilder rqBuilder = new StringBuilder();
@ -85,9 +86,9 @@ public class Request {
}
/**
* Get PrintStream --> Output
* Get PrintStream : Output
*
* @return out PrintStream --> Output
* @return out PrintStream : Output
*/
public PrintStream getOut() {
return this.out;

View File

@ -2,7 +2,6 @@ import at.reisinger.obj.Coins;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class CoinsTest {

View File

@ -16,15 +16,9 @@ public class PackageTest {
@BeforeEach
void setUp() {
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
Card newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL);
ArrayList<Card> cardsArrayList = new ArrayList<>();
ArrayList<Card> cardsArrayList2 = new ArrayList<>();
ArrayList<Card> cardsArrayList3 = new ArrayList<>();
cardsArrayList.add(card);
cardsArrayList2.add(newCard);
Cards cards = new Cards(cardsArrayList);
Cards newCards = new Cards(cardsArrayList2);
Cards nochNewCards = new Cards(cardsArrayList3);
myPackage = new Package(cards,"Name", 100);
}

View File

@ -4,8 +4,6 @@ import at.reisinger.obj.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
@ -16,27 +14,8 @@ public class TradingDealTest {
@BeforeEach
void setUp() {
//at.reisinger.Stack
card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL);
ArrayList<Card> cardsArrayList = new ArrayList<>();
ArrayList<Card> cardsArrayList2 = new ArrayList<>();
ArrayList<Card> cardsArrayList3 = new ArrayList<>();
cardsArrayList.add(card);
cardsArrayList2.add(newCard);
Cards cards = new Cards(cardsArrayList);
Cards newCards = new Cards(cardsArrayList2);
Cards nochNewCards = new Cards(cardsArrayList3);
//at.reisinger.obj.Coins
Coins coins = new Coins(10);
//at.reisinger.obj.User
Credentials credentials = new Credentials("username", "passwort");
Credentials newCredentials = new Credentials("usernamenew", "passwortnew");
User user = new User(credentials, "name", "nachname", "email", coins, "BIO", "IMAGE");
User userNew = new User(newCredentials, "nameNew", "nachnameNew", "emailNew", coins, "BIO", "IMAGE");
//Trading Deal
Card cardToTrade = card;
ElementTyp requiredElementType = ElementTyp.FIRE;
double requiredMinDamage = 100;

View File

@ -1,41 +1,16 @@
import at.reisinger.obj.*;
import at.reisinger.enums.CardType;
import at.reisinger.enums.ElementTyp;
import at.reisinger.obj.Package;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class UserTest {
private TradingDeal tradingDeal;
private User user;
private Package myPackage;
@BeforeEach
void setUp() {
//at.reisinger.Stack
Card card = new Card("Name", 10, ElementTyp.WATER, CardType.MONSTER);
Card newCard = new Card("NameNew", 10, ElementTyp.WATER, CardType.SPELL);
ArrayList<Card> cardsArrayList = new ArrayList<>();
ArrayList<Card> cardsArrayList2 = new ArrayList<>();
ArrayList<Card> cardsArrayList3 = new ArrayList<>();
cardsArrayList.add(card);
cardsArrayList2.add(newCard);
Cards cards = new Cards(cardsArrayList);
Cards newCards = new Cards(cardsArrayList2);
Cards nochNewCards = new Cards(cardsArrayList3);
//at.reisinger.obj.Package
myPackage = new Package(cards, "Name", 100);
//at.reisinger.obj.Coins
Coins coins = new Coins(10);
//at.reisinger.obj.User
Credentials credentials = new Credentials("username", "pw");
user = new User(credentials, "name", "nachname", "email", coins, "BIO", "IMAGE");
}
@ -76,10 +51,4 @@ public class UserTest {
String result = user.getEmail();
assertEquals(newstring, result);
}
@Test
public void test_buyPackage(){
Cards cards;
cards = new Cards(user.buyPackage(myPackage));
assertTrue(Objects.requireNonNull(cards).equals(new Cards(myPackage.getCards())));
}
}