programmieren-projekt/src/AiPlayer.java

27 lines
915 B
Java

import java.util.Random;
import java.awt.Point;
public abstract class AiPlayer extends Player {
public AiPlayer(int size) {
super(size);
}
public Point RandomPoint() {
Random random = new Random(); // Pseudo Random für zufallszahlen
int posx = random.nextInt(super.board.getSize()); // Generiert 0 - 13
int posy = random.nextInt(super.board.getSize()); //
return new Point(posx,posy);
}
public void AiSetShips() {
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
while(!super.board.getShips().get(i).setPosition(RandomPoint(), super.board.getShips(), super.board.getSize())) {}
} // Versucht das Aktuelle Shiff zu setzten und wiederholt solange bis es funktioniert
return;
}
public void AiShoot() {
super.board.hit(RandomPoint());
return;
}
}