Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ch.bbbaden.rio;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Manuel Saugy
- */
- public class Starter {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Gui gui = new Gui();
- RealerWuerfel realerwuerfel = new RealerWuerfel();
- Rio rio = new Rio(realerwuerfel);
- int anzahlspieler = eingabeZahl("Wie viele spielen mit? (höchstens 6)");
- Spieler[] spieler = new Spieler[anzahlspieler];
- for (int i = 0; i < anzahlspieler; i++) {
- String name = eingabeText("Namen");
- int alter = eingabeZahl("Alter");
- int anzahlStaebchen = 10;
- spieler[i] = new Spieler(name, alter, anzahlStaebchen);
- }
- Spiel spiel = new Spiel(spieler, gui, rio);
- spiel.spiele();
- }
- private static int eingabeZahl(String frage) {
- String zahlS = "";
- int zahlI = 0;
- boolean ersteDurchfuehrung = true;
- boolean umwandlungGeklappt;
- do {
- String prompt = frage;
- if (!ersteDurchfuehrung) {
- prompt = "Ungültige Eingabe\n" + frage;
- }
- zahlS = JOptionPane.showInputDialog(null, prompt, frage,
- JOptionPane.PLAIN_MESSAGE);
- ersteDurchfuehrung = false;
- umwandlungGeklappt = true;
- try {
- zahlI = Integer.parseInt(zahlS);
- } catch (NumberFormatException e) {
- umwandlungGeklappt = false;
- }
- } while (zahlS.isEmpty() || !umwandlungGeklappt);
- return zahlI;
- }
- private static String eingabeText(String frage) {
- String eingabe;
- boolean ersteDurchfuehrung = true;
- do {
- String prompt = frage;
- if (!ersteDurchfuehrung) {
- prompt = "Ungültige Eingabe\n" + frage;
- }
- eingabe = JOptionPane.showInputDialog(null, prompt, "Text eingeben", JOptionPane.PLAIN_MESSAGE);
- if (eingabe == null) {
- System.exit(0);
- }
- ersteDurchfuehrung = false;
- } while (eingabe.isEmpty());
- return eingabe;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement