added/fixed some features

This commit is contained in:
2021-04-11 22:10:42 +02:00
parent 60c59b87a9
commit 2473c31367
+32 -37
View File
@@ -9,11 +9,11 @@ public class Raumschiff {
private int lebenserhaltungssystemeInProzent; private int lebenserhaltungssystemeInProzent;
private int androidenAnzahl; private int androidenAnzahl;
private String schiffsname; private String schiffsname;
private static ArrayList<String> broadcastKommunikator; private static final ArrayList<String> broadcastKommunikator = new ArrayList<>();
private ArrayList<Ladung> ladungsverzeichnis; private final ArrayList<Ladung> ladungsverzeichnis;
public Raumschiff() { public Raumschiff() {
this.ladungsverzeichnis = new ArrayList<>();
} }
public Raumschiff(int photonentorpedoAnzahl, int energieversorgungInProzent, int schildeInProzent, int huelleInProzent, int lebenserhaltungssystemeInProzent, int androidenAnzahl, String schiffsname) { public Raumschiff(int photonentorpedoAnzahl, int energieversorgungInProzent, int schildeInProzent, int huelleInProzent, int lebenserhaltungssystemeInProzent, int androidenAnzahl, String schiffsname) {
@@ -24,6 +24,7 @@ public class Raumschiff {
this.setLebenserhaltungssystemeInProzent(lebenserhaltungssystemeInProzent); this.setLebenserhaltungssystemeInProzent(lebenserhaltungssystemeInProzent);
this.setAndroidenAnzahl(androidenAnzahl); this.setAndroidenAnzahl(androidenAnzahl);
this.setSchiffsname(schiffsname); this.setSchiffsname(schiffsname);
this.ladungsverzeichnis = new ArrayList<>();
} }
public int getPhotonentorpedoAnzahl() { public int getPhotonentorpedoAnzahl() {
@@ -89,9 +90,8 @@ public class Raumschiff {
public void photonentorpedoSchiessen(Raumschiff r) { public void photonentorpedoSchiessen(Raumschiff r) {
if (this.getPhotonentorpedoAnzahl() == 0) { if (this.getPhotonentorpedoAnzahl() == 0) {
nachrichtAnAlle("-=*Click*=-"); nachrichtAnAlle("-=*Click*=-");
} } else {
else { this.setPhotonentorpedoAnzahl(this.getPhotonentorpedoAnzahl() - 1);
this.setPhotonentorpedoAnzahl(this.getPhotonentorpedoAnzahl()-1);
nachrichtAnAlle("Photonentorpedo abgeschossen"); nachrichtAnAlle("Photonentorpedo abgeschossen");
treffer(r); treffer(r);
} }
@@ -100,39 +100,35 @@ public class Raumschiff {
public void phaserkanoneSchiessen(Raumschiff r) { public void phaserkanoneSchiessen(Raumschiff r) {
if (this.getEnergieversorgungInProzent() < 50) { if (this.getEnergieversorgungInProzent() < 50) {
nachrichtAnAlle("-=*Click*=-"); nachrichtAnAlle("-=*Click*=-");
} } else {
else { this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent() - 50);
this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent()-50);
nachrichtAnAlle("Phaserkanone abgeschossen"); nachrichtAnAlle("Phaserkanone abgeschossen");
treffer(r); treffer(r);
} }
} }
private void treffer(Raumschiff r) { private void treffer(Raumschiff r) {
System.out.println(r.getSchiffsname() + "wurde getroffen!"); System.out.println(r.getSchiffsname() + " wurde getroffen!\n");
//wenn Schilde vollständig zerstört //wenn Schilde vollständig zerstört
if (r.getSchildeInProzent() < 1) { if (r.getSchildeInProzent() < 1) {
if (r.getHuelleInProzent() < 1) { if (r.getHuelleInProzent() < 51) {
r.setLebenserhaltungssystemeInProzent(0); r.setLebenserhaltungssystemeInProzent(0);
nachrichtAnAlle("Lebenserhaltungssysteme von Raumschiff " + r.schiffsname + "vernichtet"); nachrichtAnAlle("Lebenserhaltungssysteme von Raumschiff " + r.schiffsname + " vernichtet");
} }
else {
//Hülle um 50 Prozent abbauen //Hülle um 50 Prozent abbauen
r.setHuelleInProzent(r.getHuelleInProzent() - 50); r.setHuelleInProzent(r.getHuelleInProzent() - 50);
//Energieversorgung um 50 Prozent abbauen //Energieversorgung um 50 Prozent abbauen
r.setEnergieversorgungInProzent(r.getEnergieversorgungInProzent() - 50); r.setEnergieversorgungInProzent(r.getEnergieversorgungInProzent() - 50);
} } else {
}
else {
//Schilde um 50 Prozent schwächen //Schilde um 50 Prozent schwächen
r.setSchildeInProzent(r.getSchildeInProzent()-50); r.setSchildeInProzent(r.getSchildeInProzent() - 50);
} }
} }
public void nachrichtAnAlle(String message) { public void nachrichtAnAlle(String message) {
broadcastKommunikator.add(message); broadcastKommunikator.add(this.schiffsname + ": " + message);
} }
public ArrayList<String> eintraegeLogbuchZurueckgeben() { public ArrayList<String> eintraegeLogbuchZurueckgeben() {
@@ -143,14 +139,15 @@ public class Raumschiff {
if (this.ladungPhotonentorpedosAnzahl() == 0) { if (this.ladungPhotonentorpedosAnzahl() == 0) {
System.out.println("Keine Photonentorpedos gefunden!"); System.out.println("Keine Photonentorpedos gefunden!");
nachrichtAnAlle("=*Click*=-"); nachrichtAnAlle("=*Click*=-");
} } else {
else {
//wenn Photonentorpedos mehr als in Ladung verfügbar, alle verfügbaren laden //wenn Photonentorpedos mehr als in Ladung verfügbar, alle verfügbaren laden
if (anzahlTorpedos > this.ladungPhotonentorpedosAnzahl()) if (anzahlTorpedos > this.ladungPhotonentorpedosAnzahl())
anzahlTorpedos = this.ladungPhotonentorpedosAnzahl(); anzahlTorpedos = this.ladungPhotonentorpedosAnzahl();
System.out.println(anzahlTorpedos + "Photonentorpedo(s) eingesetzt"); this.setPhotonentorpedoAnzahl(this.getPhotonentorpedoAnzahl() + anzahlTorpedos);
ladungPhotonentorpedoVermindern(anzahlTorpedos);
ladungsverzeichnisAufraeumen();
System.out.println(anzahlTorpedos + " Photonentorpedo(s) eingesetzt\n");
} }
} }
@@ -161,11 +158,9 @@ public class Raumschiff {
if (schutzschilde) { if (schutzschilde) {
anzahlTrue += 1; anzahlTrue += 1;
} } if (energieversorgung) {
else if (energieversorgung) {
anzahlTrue += 1; anzahlTrue += 1;
} } if (schiffshuelle) {
else if (schiffshuelle) {
anzahlTrue += 1; anzahlTrue += 1;
} }
@@ -173,11 +168,9 @@ public class Raumschiff {
if (schutzschilde) { if (schutzschilde) {
this.setSchildeInProzent(this.getSchildeInProzent() + reparaturErg); this.setSchildeInProzent(this.getSchildeInProzent() + reparaturErg);
} } if (energieversorgung) {
else if (energieversorgung) {
this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent() + reparaturErg); this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent() + reparaturErg);
} } if (schiffshuelle) {
else if (schiffshuelle) {
this.setHuelleInProzent(this.getHuelleInProzent() + reparaturErg); this.setHuelleInProzent(this.getHuelleInProzent() + reparaturErg);
} }
} }
@@ -190,16 +183,18 @@ public class Raumschiff {
System.out.println("huelleInProzent: " + this.huelleInProzent); System.out.println("huelleInProzent: " + this.huelleInProzent);
System.out.println("lebenserhaltungssystemeInProzent: " + this.lebenserhaltungssystemeInProzent); System.out.println("lebenserhaltungssystemeInProzent: " + this.lebenserhaltungssystemeInProzent);
System.out.println("androidenAnzahl: " + this.androidenAnzahl); System.out.println("androidenAnzahl: " + this.androidenAnzahl);
System.out.println("");
} }
public void ladungsverzeichnisAusgeben() { public void ladungsverzeichnisAusgeben() {
System.out.println("Ladungen des Raumschiffs " + this.schiffsname); System.out.println("Ladungen des Raumschiffs " + this.schiffsname);
System.out.println("============================================"); System.out.println("============================================");
for (Ladung ladung:this.ladungsverzeichnis) { for (Ladung ladung : this.ladungsverzeichnis) {
System.out.println("Ladungsbezeichnung: " + ladung.getBezeichnung()); System.out.println("Ladungsbezeichnung: " + ladung.getBezeichnung());
System.out.println("Menge: " + ladung.getMenge()); System.out.println("Menge: " + ladung.getMenge());
System.out.println("============================================"); System.out.println("============================================");
} }
System.out.println("");
} }
public void ladungsverzeichnisAufraeumen() { public void ladungsverzeichnisAufraeumen() {
@@ -208,7 +203,7 @@ public class Raumschiff {
public int ladungPhotonentorpedosAnzahl() { public int ladungPhotonentorpedosAnzahl() {
int anzahl = 0; int anzahl = 0;
for (Ladung ladung:this.ladungsverzeichnis) { for (Ladung ladung : this.ladungsverzeichnis) {
if (ladung.getBezeichnung().equalsIgnoreCase("photonentorpedos")) anzahl += ladung.getMenge(); if (ladung.getBezeichnung().equalsIgnoreCase("photonentorpedos")) anzahl += ladung.getMenge();
} }
return anzahl; return anzahl;
@@ -216,16 +211,16 @@ public class Raumschiff {
public void ladungPhotonentorpedoVermindern(int anzahl) { public void ladungPhotonentorpedoVermindern(int anzahl) {
int tempToRemove; int tempToRemove;
for (Ladung ladung:this.ladungsverzeichnis) { for (Ladung ladung : this.ladungsverzeichnis) {
if (ladung.getBezeichnung().equalsIgnoreCase("photonentorpedos") && anzahl > 0) { if (ladung.getBezeichnung().equalsIgnoreCase("photonentorpedos") && anzahl > 0) {
if (ladung.getMenge() < anzahl) { if (ladung.getMenge() < anzahl) {
tempToRemove = ladung.getMenge(); tempToRemove = ladung.getMenge();
anzahl -= tempToRemove; anzahl -= tempToRemove;
} else {
tempToRemove = anzahl;
anzahl = 0;
} }
else { ladung.setMenge(ladung.getMenge() - tempToRemove);
tempToRemove = ladung.getMenge();
}
ladung.setMenge(ladung.getMenge()-tempToRemove);
} }
} }
} }