Initial Commit

This commit is contained in:
tamara1311
2026-04-13 17:44:27 +02:00
commit d62d6132d2
18 changed files with 505 additions and 0 deletions

41
src/Cat.java Normal file
View File

@@ -0,0 +1,41 @@
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]);
if (!gArea.validatePosition(new Position(posX,posY))) {
System.out.println("Invalid input!");
System.exit(1);
}
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);
}
}