Advertisement
Guest User

Scuffed Battleship

a guest
Apr 9th, 2020
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. // Created 8 April 2020, Victor Shin
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class battleship {
  7.     public static void main(String[] args) {
  8.         String[][] ocean = new String[10][10];
  9.         Scanner input = new Scanner(System.in);
  10.  
  11. //deploy user ships
  12.  
  13.         for (int deploynumber = 0; deploynumber < 5; deploynumber++) {
  14.             System.out.print("Enter x coordinate for your ship: ");
  15.             int x = input.nextInt();
  16.             if (x > 9) {
  17.                 System.out.println("Please restart and type a number inside the coordinate plane.");
  18.                 System.exit(0);
  19.             }
  20.             System.out.print("Enter y coordinate for your ship: ");
  21.             int y = input.nextInt();
  22.             if (y > 9) {
  23.                 System.out.println("Please restart and type a number inside the coordinate plane.");
  24.                 System.exit(0);
  25.             }
  26.             char t = 'O';
  27.             String userTarget = Character.toString(t);
  28.             ocean[x][y] = userTarget;
  29.         }
  30.  
  31.  
  32. //map~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33.  
  34.         public static void printMap(){
  35.            
  36.         }
  37.         System.out.println("  0123456789  ");
  38.         for (int row = 0; row < ocean.length; row++) {
  39.             System.out.print(row + "|");
  40.             for (int column = 0; column < ocean[row].length; column++) {
  41.                 if (ocean[row][column] == null) {
  42.                     System.out.print(" ");
  43.                 } else {
  44.                     System.out.print(ocean[row][column]);
  45.                 }
  46.             }
  47.             System.out.println("|" + row);
  48.         }
  49.  
  50.         System.out.println("  0123456789  ");
  51.  
  52. //map~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53.  
  54.  
  55.         // AI deploy 5 ships random
  56.         Random rand = new Random();
  57.         String[][] aiShips = new String[10][10];
  58.  
  59.  
  60.         for(int AIdeploy = 0; AIdeploy<5; AIdeploy++) {
  61.             int AIx = rand.nextInt(9);
  62.             int AIy = rand.nextInt(9);
  63.             aiShips[AIx][AIy] = "aiShip";
  64.         }
  65.  
  66.  
  67. //        while(ship # == 0)
  68.         System.out.print("Type in the x coordinate you wish to attack: ");
  69.         int x = input.nextInt();
  70.         System.out.print("Type in the y coordinate you wish to attack: ");
  71.         int y = input.nextInt();
  72.         if (aiShips[x][y] == "aiShip") {
  73.             System.out.print("You sunk a ship!");
  74.             char h = '#';
  75.             String j = Character.toString(h);
  76.             ocean[x][y] = j;
  77.  
  78.             //map needs to go here
  79.            
  80.         } else if(aiShips[x][y] == null){
  81.             System.out.print("You missed!");
  82.             ocean[x][y] = "N";
  83.             //map needs to go here
  84.         }
  85.  
  86.  
  87.     }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement