added number input
This commit is contained in:
@@ -4,13 +4,24 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class Input {
|
public class Input {
|
||||||
|
|
||||||
Scanner s;
|
private static Scanner s;
|
||||||
|
|
||||||
public Input() {
|
static {
|
||||||
s = new Scanner(System.in);
|
s = new Scanner(System.in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int scanFieldInput() {
|
||||||
|
String input;
|
||||||
|
do {
|
||||||
|
input = s.next();
|
||||||
|
if (!input.contains("[0-9]+")) {
|
||||||
|
System.out.println("Bitte eine Zahl eingeben!");
|
||||||
|
}
|
||||||
|
} while (!input.contains("[0-9]+"));
|
||||||
|
return Integer.parseInt(input);
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public static void close() {
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
public class Player {
|
public class Player {
|
||||||
|
|
||||||
|
private char symbol;
|
||||||
|
|
||||||
|
public Player(char symbol) {
|
||||||
|
this.symbol = symbol;
|
||||||
|
}
|
||||||
|
|
||||||
public void makeTurn() {
|
public void makeTurn() {
|
||||||
|
System.out.println(symbol + " ist am Zug!");
|
||||||
|
int in = Input.scanFieldInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ public class TicTacToe {
|
|||||||
|
|
||||||
Player player1, player2;
|
Player player1, player2;
|
||||||
Player turn;
|
Player turn;
|
||||||
|
|
||||||
public static Input input = new Input();
|
|
||||||
|
|
||||||
private boolean running;
|
private boolean running;
|
||||||
|
|
||||||
public TicTacToe() {
|
public TicTacToe() {
|
||||||
player1 = new Player();
|
player1 = new Player('X');
|
||||||
player2 = new Player();
|
player2 = new Player('O');
|
||||||
turn = player1;
|
turn = player1;
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
@@ -32,7 +30,7 @@ public class TicTacToe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
input.close();
|
Input.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user