added number input
This commit is contained in:
@@ -4,13 +4,24 @@ import java.util.Scanner;
|
||||
|
||||
public class Input {
|
||||
|
||||
Scanner s;
|
||||
private static Scanner s;
|
||||
|
||||
public Input() {
|
||||
static {
|
||||
s = new Scanner(System.in);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
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 static void close() {
|
||||
s.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,15 @@ package main;
|
||||
|
||||
public class Player {
|
||||
|
||||
public void makeTurn() {
|
||||
private char symbol;
|
||||
|
||||
public Player(char symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public void makeTurn() {
|
||||
System.out.println(symbol + " ist am Zug!");
|
||||
int in = Input.scanFieldInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,13 +5,11 @@ public class TicTacToe {
|
||||
Player player1, player2;
|
||||
Player turn;
|
||||
|
||||
public static Input input = new Input();
|
||||
|
||||
private boolean running;
|
||||
|
||||
public TicTacToe() {
|
||||
player1 = new Player();
|
||||
player2 = new Player();
|
||||
player1 = new Player('X');
|
||||
player2 = new Player('O');
|
||||
turn = player1;
|
||||
|
||||
running = true;
|
||||
@@ -32,7 +30,7 @@ public class TicTacToe {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
input.close();
|
||||
Input.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user