forked from 2211945/WIZARD_PR2_DOP
Merge pull request 'Spiel_feat persistenz SpeilCLI und weiteres' (#16) from Spiel_feat into main
Reviewed-on: 2211945/WIZARD_PR2_DOP#16
commit
eaa7831208
|
@ -0,0 +1,7 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="20 (2)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/WIAZRD_DOP_PR2.iml" filepath="$PROJECT_DIR$/WIAZRD_DOP_PR2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -8,7 +8,9 @@ package Domain;
|
|||
|
||||
import Domain.Enums.Geschlecht;
|
||||
|
||||
public class Spieler {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Spieler implements Serializable {
|
||||
|
||||
// Statische Konstanten
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@ written on: 05 / 10 / 2023 at: 23:25
|
|||
*/
|
||||
package Facade;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import Domain.Spieler;
|
||||
import Domain.Enums.Geschlecht;
|
||||
|
||||
public class Spiel {
|
||||
public class Spiel implements Serializable {
|
||||
|
||||
private boolean istGestartet;
|
||||
private boolean istBeendet;
|
||||
|
|
|
@ -6,6 +6,32 @@ written on: 05 / 10 / 2023 at: 23:25
|
|||
*/
|
||||
package Infrastructure;
|
||||
|
||||
import Facade.Spiel;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class Persistenz {
|
||||
|
||||
final static String FILE_NAME = "WIZARD_DATA_";
|
||||
|
||||
public static boolean sindDatenVorhanden(String name){
|
||||
File f = new File(FILE_NAME + name + ".ser");
|
||||
if(f.exists()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void speichereDaten(String name, Spiel spiel) throws IOException {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(FILE_NAME + name + ".ser"));
|
||||
oos.writeObject(spiel);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
public static Object ladeDaten(String name) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILE_NAME + name + ".ser"));
|
||||
Object spiel = ois.readObject();
|
||||
ois.close();
|
||||
return spiel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import Facade.Spiel;
|
||||
import Infrastructure.Persistenz;
|
||||
import UI.SpielCLI;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
String name = "Wizard";
|
||||
Spiel spiel = null;
|
||||
|
||||
if (Persistenz.sindDatenVorhanden(name)) {
|
||||
try {
|
||||
System.out.println("Lade daten");
|
||||
spiel = (Spiel) Persistenz.ladeDaten(name);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Konnte file nicht laden.");
|
||||
System.out.println(e.getLocalizedMessage());
|
||||
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
System.out.println("Konnte file nicht laden.");
|
||||
System.out.println(cnfe.getLocalizedMessage());
|
||||
} finally {
|
||||
if (spiel == null) {
|
||||
System.out.println("Initialisiere neues Spiel");
|
||||
spiel = new Spiel();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
spiel = new Spiel();
|
||||
}
|
||||
|
||||
new SpielCLI(spiel);
|
||||
|
||||
try {
|
||||
Persistenz.speichereDaten(name, spiel);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Konnte Daten nicht speicher!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,8 +7,47 @@ written on: 05 / 10 / 2023 at: 23:25
|
|||
|
||||
package UI;
|
||||
|
||||
import Facade.Spiel;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SpielCLI {
|
||||
int x = 12;
|
||||
|
||||
//Kommentar
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
private Spiel spiel;
|
||||
|
||||
public SpielCLI(Spiel spiel) {
|
||||
this.spiel = spiel;
|
||||
hauptmenue();
|
||||
}
|
||||
|
||||
public void hauptmenue() {
|
||||
mainloop: while (true) {
|
||||
System.out.println("Hallo Wanderer");
|
||||
System.out.println("Was sillst du tun");
|
||||
System.out.println("--------Hauptmenü--------");
|
||||
System.out.println("-1- Spiel starten");
|
||||
System.out.println("-2- Exit");
|
||||
|
||||
int input = 0;
|
||||
|
||||
try {
|
||||
input = Integer.parseInt(sc.nextLine());
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("Diese eingabe ist ungültig.");
|
||||
}
|
||||
|
||||
switch (input) {
|
||||
case 1:
|
||||
System.out.println("Noch nicht implementiert.");
|
||||
break;
|
||||
case 2:
|
||||
break mainloop;
|
||||
case 0:
|
||||
System.out.println("Diese eingabe ist nicht vergeben.");
|
||||
}
|
||||
}
|
||||
System.out.println("auf wiedersehen!");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue