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$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="JavaSE-13" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
</component>
</module>
-1
View File
@@ -1 +0,0 @@
/Angestellter/
+29
View File
@@ -1,2 +1,31 @@
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);
}
}
+137 -21
View File
@@ -1,4 +1,5 @@
import java.util.ArrayList;
import java.util.Random;
public class Raumschiff {
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) {
this.photonentorpedoAnzahl = photonentorpedoAnzahl;
this.energieversorgungInProzent = energieversorgungInProzent;
this.schildeInProzent = schildeInProzent;
this.huelleInProzent = huelleInProzent;
this.lebenserhaltungssystemeInProzent = lebenserhaltungssystemeInProzent;
this.androidenAnzahl = androidenAnzahl;
this.schiffsname = schiffsname;
this.ladungsverzeichnis = ladungsverzeichnis;
public Raumschiff(int photonentorpedoAnzahl, int energieversorgungInProzent, int schildeInProzent, int huelleInProzent, int lebenserhaltungssystemeInProzent, int androidenAnzahl, String schiffsname) {
this.setPhotonentorpedoAnzahl(photonentorpedoAnzahl);
this.setEnergieversorgungInProzent(energieversorgungInProzent);
this.setSchildeInProzent(schildeInProzent);
this.setHuelleInProzent(huelleInProzent);
this.setLebenserhaltungssystemeInProzent(lebenserhaltungssystemeInProzent);
this.setAndroidenAnzahl(androidenAnzahl);
this.setSchiffsname(schiffsname);
}
public int getPhotonentorpedoAnzahl() {
@@ -82,35 +82,151 @@ public class Raumschiff {
this.schiffsname = schiffsname;
}
public void addLadung (Ladung neueLadung) {
public void addLadung(Ladung neueLadung) {
this.ladungsverzeichnis.add(neueLadung);
}
public void photonentorpedoSchiessen (Raumschiff r) {
//TODO
public void photonentorpedoSchiessen(Raumschiff r) {
if (this.getPhotonentorpedoAnzahl() == 0) {
nachrichtAnAlle("-=*Click*=-");
}
else {
this.setPhotonentorpedoAnzahl(this.getPhotonentorpedoAnzahl()-1);
nachrichtAnAlle("Photonentorpedo abgeschossen");
treffer(r);
}
}
public void phaserkanoneSchiessen (Raumschiff r) {
//TODO
public void phaserkanoneSchiessen(Raumschiff r) {
if (this.getEnergieversorgungInProzent() < 50) {
nachrichtAnAlle("-=*Click*=-");
}
else {
this.setEnergieversorgungInProzent(this.getEnergieversorgungInProzent()-50);
nachrichtAnAlle("Phaserkanone abgeschossen");
treffer(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) {
//TODO
broadcastKommunikator.add(message);
}
public ArrayList<String> eintraegeLogbuchZurueckgeben() {
//TODO
return null;
return broadcastKommunikator;
}
public void photonentorpedosLaden(int anzahlTorpedos){
//TODO
public void photonentorpedosLaden(int anzahlTorpedos) {
if (this.ladungPhotonentorpedosAnzahl() == 0) {
System.out.println("Keine Photonentorpedos gefunden!");
nachrichtAnAlle("=*Click*=-");
}
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 schiffshuell)
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">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />