import java.util.Scanner; public class GameBattleShip { public static void main(String[] args) throws Exception { System.out.println("Welcome to the Game ShipBattle! You will have to shank 3 ships!"); String [][] board = new String [7][7]; Ship one = new Ship(); one.name = "Angela"; Ship two = new Ship(); Ship three = new Ship(); GameHelper assistant = new GameHelper(); //CREATE THREE SHIP WTHOUT ANY COMMON CELL ADDRESSS IN THE BOARD if (!assistant.areShipCrashed(one, two)) { two.name = "Hitler"; } else { boolean failTest = assistant.areShipCrashed(one, two); while (failTest) { two = new Ship(); two.name = "Hitler"; failTest = assistant.areShipCrashed(one, two); } } if (!assistant.areShipCrashed(one, three) && !assistant.areShipCrashed(two, three)) { three.name = "Napoleon"; } else { boolean failTest1 = assistant.areShipCrashed(one, three); boolean failTest2 = assistant.areShipCrashed(two, three); while (!(!failTest1 && !failTest2)) { three = new Ship(); three.name = "Napoleon"; failTest1 = assistant.areShipCrashed(one, three); failTest2 = assistant.areShipCrashed(two, three); } } System.out.println(one.name + " is created"); assistant.setAngelaLoc(one.shipLocation); System.out.println(two.name + " is created"); assistant.setHitlerLoc(two.shipLocation); System.out.println(three.name + " is created"); assistant.setNapoleonLoc(three.shipLocation); System.out.println(); System.out.println("WELCOME TO THE BATTLESHIPS WAR. You have to Destroy 3 ships to win "); GameHelper.setNewBoard(board); GameHelper.printCurrentBoard(board); System.out.println("AIM, READY? FIRE on your Location XY -Which X runs (0-6) & Y runs (0-6): Example: 06,13,15... "); while (!assistant.isTheGameEnd()) { String guess; Scanner scan = new Scanner(System.in); System.out.println("This is your " + (GameHelper.countFire+1) + "'s shoot... GO"); GameHelper.countFire++; System.out.println("Log in Location XY to FIRE: "); //loop start here guess = scan.nextLine(); String check = assistant.checkTheFireResult(guess); System.out.println(check); GameHelper.updateCurrentBoard(check, board, guess); GameHelper.printCurrentBoard(board); System.out.println("You have shoot " + GameHelper.countFire + " times"); if (assistant.angelaShip.isEmpty()) { System.out.println(" Great! you've Terminated ANGELASHIP"); } if (assistant.hitlerShip.isEmpty()) { System.out.println(" Great! you've Terminated HITLERSHIP"); } if (assistant.napoleonShip.isEmpty()) { System.out.println(" Great! you've Terminated NAPOLEONSHIP"); } System.out.println(); System.out.println("Next ROUND... READY?! "); } System.out.println("YOU DESTROYED ALL SHIPS! CONGRAT you win after " + GameHelper.countFire + " attempts"); } }