implemented Ladung, Raumschiff classes + their methods

This commit is contained in:
2021-04-11 20:53:47 +02:00
parent e87fc10cf3
commit 60c59b87a9
5 changed files with 168 additions and 24 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content> </content>
<orderEntry type="jdk" jdkName="JavaSE-13" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
</component> </component>
</module> </module>
-1
View File
@@ -1 +0,0 @@
/Angestellter/
+29
View File
@@ -1,2 +1,31 @@
public class Ladung { public class Ladung {
private String bezeichnung;
private int menge;
public Ladung() {
}
public Ladung(String bezeichnung, int menge) {
this.setBezeichnung(bezeichnung);
this.setMenge(menge);
}
public String getBezeichnung() {
return bezeichnung;
}
public void setBezeichnung(String bezeichnung) {
this.bezeichnung = bezeichnung;
}
public int getMenge() {
return menge;
}
public void setMenge(int menge) {
this.menge = Math.max(menge, 0);
}
} }
+133 -17
View File
@@ -1,4 +1,5 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
public class Raumschiff { public class Raumschiff {
private int photonentorpedoAnzahl; private int photonentorpedoAnzahl;
@@ -15,15 +16,14 @@ public class Raumschiff {
} }
public Raumschiff(int photonentorpedoAnzahl, int energieversorgungInProzent, int schildeInProzent, int huelleInProzent, int lebenserhaltungssystemeInProzent, int androidenAnzahl, String schiffsname, ArrayList<Ladung> ladungsverzeichnis) { public Raumschiff(int photonentorpedoAnzahl, int energieversorgungInProzent, int schildeInProzent, int huelleInProzent, int lebenserhaltungssystemeInProzent, int androidenAnzahl, String schiffsname) {
this.photonentorpedoAnzahl = photonentorpedoAnzahl; this.setPhotonentorpedoAnzahl(photonentorpedoAnzahl);
this.energieversorgungInProzent = energieversorgungInProzent; this.setEnergieversorgungInProzent(energieversorgungInProzent);
this.schildeInProzent = schildeInProzent; this.setSchildeInProzent(schildeInProzent);
this.huelleInProzent = huelleInProzent; this.setHuelleInProzent(huelleInProzent);
this.lebenserhaltungssystemeInProzent = lebenserhaltungssystemeInProzent; this.setLebenserhaltungssystemeInProzent(lebenserhaltungssystemeInProzent);
this.androidenAnzahl = androidenAnzahl; this.setAndroidenAnzahl(androidenAnzahl);
this.schiffsname = schiffsname; this.setSchiffsname(schiffsname);
this.ladungsverzeichnis = ladungsverzeichnis;
} }
public int getPhotonentorpedoAnzahl() { public int getPhotonentorpedoAnzahl() {
@@ -87,30 +87,146 @@ public class Raumschiff {
} }
public void photonentorpedoSchiessen(Raumschiff r) { public void photonentorpedoSchiessen(Raumschiff r) {
//TODO if (this.getPhotonentorpedoAnzahl() == 0) {
nachrichtAnAlle("-=*Click*=-");
}
else {
this.setPhotonentorpedoAnzahl(this.getPhotonentorpedoAnzahl()-1);
nachrichtAnAlle("Photonentorpedo abgeschossen");
treffer(r);
}
} }
public void phaserkanoneSchiessen(Raumschiff r) { public void phaserkanoneSchiessen(Raumschiff r) {
//TODO if (this.getEnergieversorgungInProzent() < 50) {
nachrichtAnAlle("-=*Click*=-");
}
else {
this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent()-50);
nachrichtAnAlle("Phaserkanone abgeschossen");
treffer(r);
}
} }
private void treffer(Raumschiff r) { private void treffer(Raumschiff r) {
//TODO System.out.println(r.getSchiffsname() + "wurde getroffen!");
//wenn Schilde vollständig zerstört
if (r.getSchildeInProzent() < 1) {
if (r.getHuelleInProzent() < 1) {
r.setLebenserhaltungssystemeInProzent(0);
nachrichtAnAlle("Lebenserhaltungssysteme von Raumschiff " + r.schiffsname + "vernichtet");
}
else {
//Hülle um 50 Prozent abbauen
r.setHuelleInProzent(r.getHuelleInProzent() - 50);
//Energieversorgung um 50 Prozent abbauen
r.setEnergieversorgungInProzent(r.getEnergieversorgungInProzent() - 50);
}
}
else {
//Schilde um 50 Prozent schwächen
r.setSchildeInProzent(r.getSchildeInProzent()-50);
}
} }
public void nachrichtAnAlle(String message) { public void nachrichtAnAlle(String message) {
//TODO broadcastKommunikator.add(message);
} }
public ArrayList<String> eintraegeLogbuchZurueckgeben() { public ArrayList<String> eintraegeLogbuchZurueckgeben() {
//TODO return broadcastKommunikator;
return null;
} }
public void photonentorpedosLaden(int anzahlTorpedos) { public void photonentorpedosLaden(int anzahlTorpedos) {
//TODO if (this.ladungPhotonentorpedosAnzahl() == 0) {
System.out.println("Keine Photonentorpedos gefunden!");
nachrichtAnAlle("=*Click*=-");
} }
public void reparaturDurchfuehren(boolean schutzschilde, boolean energieversorgung, boolean schiffshuell) else {
//wenn Photonentorpedos mehr als in Ladung verfügbar, alle verfügbaren laden
if (anzahlTorpedos > this.ladungPhotonentorpedosAnzahl())
anzahlTorpedos = this.ladungPhotonentorpedosAnzahl();
System.out.println(anzahlTorpedos + "Photonentorpedo(s) eingesetzt");
}
}
public void reparaturDurchfuehren(boolean schutzschilde, boolean energieversorgung, boolean schiffshuelle, int anzahlDroiden) {
Random random = new Random();
int zufallszahl = random.nextInt(100);
int anzahlTrue = 0;
if (schutzschilde) {
anzahlTrue += 1;
}
else if (energieversorgung) {
anzahlTrue += 1;
}
else if (schiffshuelle) {
anzahlTrue += 1;
}
int reparaturErg = (zufallszahl * anzahlDroiden) / anzahlTrue;
if (schutzschilde) {
this.setSchildeInProzent(this.getSchildeInProzent() + reparaturErg);
}
else if (energieversorgung) {
this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent() + reparaturErg);
}
else if (schiffshuelle) {
this.setHuelleInProzent(this.getHuelleInProzent() + reparaturErg);
}
}
public void zustandRaumschiff() {
System.out.println("Schiffsname: " + this.schiffsname);
System.out.println("photonentorpedoAnzahl: " + this.photonentorpedoAnzahl);
System.out.println("energieversorgungInProzent: " + this.energieversorgungInProzent);
System.out.println("schildeInProzent: " + this.schildeInProzent);
System.out.println("huelleInProzent: " + this.huelleInProzent);
System.out.println("lebenserhaltungssystemeInProzent: " + this.lebenserhaltungssystemeInProzent);
System.out.println("androidenAnzahl: " + this.androidenAnzahl);
}
public void ladungsverzeichnisAusgeben() {
System.out.println("Ladungen des Raumschiffs " + this.schiffsname);
System.out.println("============================================");
for (Ladung ladung:this.ladungsverzeichnis) {
System.out.println("Ladungsbezeichnung: " + ladung.getBezeichnung());
System.out.println("Menge: " + ladung.getMenge());
System.out.println("============================================");
}
}
public void ladungsverzeichnisAufraeumen() {
ladungsverzeichnis.removeIf(ladung -> ladung.getMenge() == 0);
}
public int ladungPhotonentorpedosAnzahl() {
int anzahl = 0;
for (Ladung ladung:this.ladungsverzeichnis) {
if (ladung.getBezeichnung().equalsIgnoreCase("photonentorpedos")) anzahl += ladung.getMenge();
}
return anzahl;
}
public void ladungPhotonentorpedoVermindern(int anzahl) {
int tempToRemove;
for (Ladung ladung:this.ladungsverzeichnis) {
if (ladung.getBezeichnung().equalsIgnoreCase("photonentorpedos") && anzahl > 0) {
if (ladung.getMenge() < anzahl) {
tempToRemove = ladung.getMenge();
anzahl -= tempToRemove;
}
else {
tempToRemove = ladung.getMenge();
}
ladung.setMenge(ladung.getMenge()-tempToRemove);
}
}
}
} }
@@ -3,7 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />