Skip to content

Commit d881310

Browse files
committed
Pick amount of players
1 parent 41f2546 commit d881310

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed
-1 Bytes
Binary file not shown.
2.21 KB
Binary file not shown.

src/Model/Game.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Game {
66
Tisch table;
77
Spieler[] players;
88
int turns = 0;
9-
public Game(int playercount, Stapel s, Tisch t) {
9+
public Game(Integer playercount, Stapel s, Tisch t) {
1010
this.playercount = playercount;
1111
this.stack = s;
1212
this.table = t;

src/TschauSeppApp.java

+40-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,49 @@
22
import Model.Spieler;
33
import Model.Stapel;
44
import Model.Tisch;
5+
import javafx.scene.control.RadioButton;
6+
7+
import javax.swing.*;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
510

611
public class TschauSeppApp {
712
public static void main(String[] args) {
8-
int playerAmount = 4;
9-
Stapel stack = new Stapel();
10-
Tisch table = new Tisch();
11-
Game game = new Game(playerAmount, stack, table);
12-
Frame f = new Frame(game);
13+
JFrame frame = new JFrame();
14+
JPanel panel = new JPanel();
15+
JLabel L = new JLabel(
16+
"Bitte schreiben sie eine gewünschte Anzahl von Spieler");
17+
panel.add(L);
18+
JTextField text = new JTextField();
19+
text.setColumns(5);
20+
panel.add(text);
21+
JButton button = new JButton("Enter");
22+
button.addActionListener(actionEvent -> {
23+
if (isInteger(text.getText()) && (Integer.parseInt(text.getText())<=8 || Integer.parseInt(text.getText())>=2)){
24+
frame.setVisible(false);
25+
frame.dispose();
26+
Stapel stack = new Stapel();
27+
Tisch table = new Tisch();
28+
Game game = new Game(Integer.parseInt(text.getText()), stack, table);
29+
Frame f = new Frame(game);
30+
} else {
31+
JOptionPane.showMessageDialog(frame,"Bitte schreiben sie eine Zahl zwischen 2 und 8");
32+
}
33+
});
34+
panel.add(button);
35+
frame.add(panel);
36+
frame.pack();
37+
frame.setVisible(true);
38+
39+
}
40+
public static boolean isInteger( String input ) {
41+
try {
42+
Integer.parseInt( input );
43+
return true;
44+
}
45+
catch( Exception e ) {
46+
return false;
47+
}
1348
}
1449
}
1550

0 commit comments

Comments
 (0)