import java.io.IOException; import java.util.Random; import java.util.Scanner; public class Cat extends Player{ Scanner scanner = new Scanner(System.in); public Cat(Position p, GamingArea g, Game ga) throws IOException { super(p, g, ga); p.displayChar = DisplayChars.TOM.getCharacter(); } @Override public void movePlayer() throws IOException { System.out.print("Tom moves to (line-column): "); String input = scanner.next(); if (!input.matches("^[0-9]+-[0-9]+$")) { System.out.println("Invalid input!"); System.exit(1); } String inputArr[] = input.split("-"); int posX = Integer.parseInt(inputArr[0]); int posY = Integer.parseInt(inputArr[1]); movePlayer(posX, posY); } public void movePlayer(int posX, int posY) throws IOException { if (!gArea.validatePosition(new Position(posX,posY))) { System.out.println("Invalid input!"); if (scanner != null && scanner.hasNext()) System.exit(1); // Only exit if in console mode return; } Position p = gArea.playingField[posX][posY]; p.displayChar = DisplayChars.TOM.getCharacter(); game.writer.write("Tom moves from " + positionPlayer.posX+ "-" + positionPlayer.posY + " to " + posX + "-" + posY); game.writer.newLine(); movePlayer(p); } }