rendered paste bodypackage Battleship;
import java.util.Scanner;
public class textInterface {
private Scanner input = new Scanner(System.in);
private Battleship battleship;
private Board board;
private AI ai;
public void fire(Board board) {
System.out.println("Target X coordinate: ");
int x = input.nextInt();
System.out.println("Target Y coordinate: ");
int y = input.nextInt();
System.out.println("You fired at target coordinate (" + x + ", " + y + ")");
if(board.hit(x, y)) {
System.out.println("DIRECT HIT!");
} else {
System.out.println("EPIC MISS");
}
}
public String drawMap(Board board) {
String s = "";
for (int i = 0; i < board.getWidth(); i++) {
for (int j = 0; j < board.getHeight(); j++) {
s += " " + board.getMap()[i][j];
}
s+="\n\n";
}
return s;
}
public void runGame() {
board = new Board(10,10);
battleship = new Battleship(10,10,board);
ai = new AI();
boolean gameOn = true;
for (int i = 0; i < 2; i++) {
if(!ai.generateShip(board)) {
return;
}
}
System.out.println(board.getShips().get(0).getLength());
System.out.println(board.getShips().get(0).getDirection().toString());
System.out.println(board.getShips().get(1).getLength());
System.out.println(board.getShips().get(1).getDirection().toString());
while(gameOn) {
System.out.println(drawMap(board));
fire(board);
}
}
public static void main(String[]args) {
textInterface t = new textInterface();
t.runGame();
}
}