added number input

This commit is contained in:
Asecave
2020-09-02 21:34:30 +02:00
parent 2c4338ac9a
commit 8020515432
3 changed files with 25 additions and 9 deletions

View File

@@ -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();
} }

View File

@@ -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();
} }
} }

View File

@@ -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();
} }
} }