Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created 8 April 2020, Victor Shin
- import java.util.Random;
- import java.util.Scanner;
- public class battleship {
- public static void main(String[] args) {
- String[][] ocean = new String[10][10];
- Scanner input = new Scanner(System.in);
- //deploy user ships
- for (int deploynumber = 0; deploynumber < 5; deploynumber++) {
- System.out.print("Enter x coordinate for your ship: ");
- int x = input.nextInt();
- if (x > 9) {
- System.out.println("Please restart and type a number inside the coordinate plane.");
- System.exit(0);
- }
- System.out.print("Enter y coordinate for your ship: ");
- int y = input.nextInt();
- if (y > 9) {
- System.out.println("Please restart and type a number inside the coordinate plane.");
- System.exit(0);
- }
- char t = 'O';
- String userTarget = Character.toString(t);
- ocean[x][y] = userTarget;
- }
- //map~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public static void printMap(){
- }
- System.out.println(" 0123456789 ");
- for (int row = 0; row < ocean.length; row++) {
- System.out.print(row + "|");
- for (int column = 0; column < ocean[row].length; column++) {
- if (ocean[row][column] == null) {
- System.out.print(" ");
- } else {
- System.out.print(ocean[row][column]);
- }
- }
- System.out.println("|" + row);
- }
- System.out.println(" 0123456789 ");
- //map~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // AI deploy 5 ships random
- Random rand = new Random();
- String[][] aiShips = new String[10][10];
- for(int AIdeploy = 0; AIdeploy<5; AIdeploy++) {
- int AIx = rand.nextInt(9);
- int AIy = rand.nextInt(9);
- aiShips[AIx][AIy] = "aiShip";
- }
- // while(ship # == 0)
- System.out.print("Type in the x coordinate you wish to attack: ");
- int x = input.nextInt();
- System.out.print("Type in the y coordinate you wish to attack: ");
- int y = input.nextInt();
- if (aiShips[x][y] == "aiShip") {
- System.out.print("You sunk a ship!");
- char h = '#';
- String j = Character.toString(h);
- ocean[x][y] = j;
- //map needs to go here
- } else if(aiShips[x][y] == null){
- System.out.print("You missed!");
- ocean[x][y] = "N";
- //map needs to go here
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement