uebung09
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package chess;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
@@ -12,6 +13,7 @@ public class ChessApp {
|
||||
private static final String BLACK_QUEEN = "Q";
|
||||
private static final String WHITE_KNIGHT = "n";
|
||||
private static final String BLACK_KNIGHT = "N";
|
||||
private static final String ITERATOR = "i";
|
||||
|
||||
private final Scanner scanner;
|
||||
private final Board board;
|
||||
@@ -44,6 +46,7 @@ public class ChessApp {
|
||||
case WHITE_QUEEN -> addQueen(Color.white);
|
||||
case BLACK_KNIGHT -> addKnight(Color.black);
|
||||
case WHITE_KNIGHT -> addKnight(Color.white);
|
||||
case ITERATOR -> iterate();
|
||||
default -> System.out.println("Invalid command " + command);
|
||||
}
|
||||
}
|
||||
@@ -70,6 +73,15 @@ public class ChessApp {
|
||||
board.printBoard();
|
||||
}
|
||||
|
||||
private void iterate() {
|
||||
final Iterator<Piece> it = board.iterator();
|
||||
|
||||
|
||||
while (it.hasNext()) {
|
||||
System.out.println(it.next());
|
||||
}
|
||||
}
|
||||
|
||||
private void help() {
|
||||
System.out.println("Commands:");
|
||||
System.out.println(ABORT + ": terminate the program");
|
||||
@@ -78,5 +90,6 @@ public class ChessApp {
|
||||
System.out.println(BLACK_KNIGHT + " <int> <int>: place a new black knight at specified position");
|
||||
System.out.println(WHITE_QUEEN + " <int> <int>: place a new white queen at specified position");
|
||||
System.out.println(BLACK_QUEEN + " <int> <int>: place a new black queen at specified position");
|
||||
System.out.println(ITERATOR + ": iterate over the board and print all pieces to the console");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user