Browse Source
Battleship incomplete.
Battleship incomplete.
Added rotate and create random methods to ship and debugged Ship.javaexperiment
3 changed files with 197 additions and 56 deletions
-
81Battleship.java
-
126Ship.java
-
46ShipTest.java
@ -1,39 +1,21 @@ |
|||
import java.util.Scanner; |
|||
public class ShipTest{ |
|||
public static void testShips(Ship ship1, Ship ship2,String name){ |
|||
System.out.println("Testing " + name); |
|||
ship1.print(); |
|||
System.out.println(); |
|||
ship2.print(); |
|||
System.out.println(ship1.intersects(ship2)+"=="+ship2.intersects(ship1)); |
|||
public static void createTestShips(int[] start,int[] end, Ship[] fill){ |
|||
for (int i = 0; i < fill.length; i++){ |
|||
fill[i] = Ship.randomShip(start,end,Ship.randint(2,4),true); |
|||
} |
|||
} |
|||
|
|||
public static void main(String[] args){ |
|||
int[] ship1start = new int[2]; |
|||
int[] ship1end = new int[2]; |
|||
|
|||
int[] ship2start = new int[2]; |
|||
int[] ship2end = new int[2]; |
|||
String name; |
|||
while (true) { |
|||
Scanner input = new Scanner(System.in); |
|||
System.out.print("Enter test name: "); |
|||
name = input.nextLine(); |
|||
|
|||
System.out.print("Enter ship1 start: "); |
|||
ship1start[0] = input.nextInt(); |
|||
ship1start[1] = input.nextInt(); |
|||
System.out.print("Enter ship1 end: "); |
|||
ship1end[0] = input.nextInt(); |
|||
ship1end[1] = input.nextInt(); |
|||
|
|||
System.out.print("Enter ship2 start: "); |
|||
ship2start[0] = input.nextInt(); |
|||
ship2start[1] = input.nextInt(); |
|||
System.out.print("Enter ship2 end: "); |
|||
ship2end[0] = input.nextInt(); |
|||
ship2end[1] = input.nextInt(); |
|||
Ship[] test_ships = new Ship[5]; |
|||
createTestShips(new int[] {0,0}, new int[] {5,5},test_ships); |
|||
for (int i = 0; i < test_ships.length-1;i++){ |
|||
test_ships[i].print(); |
|||
System.out.println(); |
|||
test_ships[i+1].print(); |
|||
|
|||
testShips(new Ship(ship1start,ship1end),new Ship(ship2start,ship2end),name); |
|||
System.out.println(test_ships[i].isIntersecting(test_ships[i+1])); |
|||
System.out.println(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue