Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.Arrays;
- import java.util.Scanner;
- public class battleship {
- public static char[][] display = new char[][]{
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- };
- public static char[][] hidden = new char[][]{
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.'},
- };
- public static int missCount = 0;
- public static int hitCount = 0;
- public static String location;
- public static void main(String args[]) {
- Scanner myScanner = new Scanner(System.in);
- location = myScanner;
- userDisplay();
- System.out.println();
- setUp();
- System.out.println();
- hidden();
- }
- public static void userDisplay() {
- System.out.println(" 0 1 2 3 4 ");
- for (int i = 0; i < 5; i++) {
- System.out.print(i + " ");
- for (int j = 0; j < display[i].length; j++) {
- System.out.print(display[i][j] + " ");
- }
- System.out.println();
- }
- }
- public static void hidden() {
- System.out.println(" 0 1 2 3 4 ");
- for (int i = 0; i < 5; i++) {
- System.out.print(i + " ");
- for (int j = 0; j < hidden[i].length; j++) {
- System.out.print(hidden[i][j] + " ");
- }
- System.out.println();
- }
- }
- public static void setUp() {
- int shipStartRow = (int) (Math.random() * 5); //row
- int shipStartCol = (int) (Math.random() * 5); //col
- int shipBuildDir = (int) (Math.random() * 2);
- System.out.println("col is: " + shipStartCol + " row is :" + shipStartRow);
- System.out.println("direction is: " + shipBuildDir);
- System.out.println(Math.random());
- if (shipBuildDir == 0) {
- if (shipStartCol > 2) {
- hidden[shipStartRow][shipStartCol] = 'S';
- hidden[shipStartRow][shipStartCol - 1] = 'S';
- hidden[shipStartRow][shipStartCol - 2] = 'S';
- } else /*if (shipStartCol < 2)*/ {
- hidden[shipStartRow][shipStartCol] = 'S';
- hidden[shipStartRow][shipStartCol + 1] = 'S';
- hidden[shipStartRow][shipStartCol + 2] = 'S';
- }
- }
- if (shipBuildDir == 1) {
- if (shipStartRow > 2) {
- hidden[shipStartRow][shipStartCol] = 'S';
- hidden[shipStartRow - 1][shipStartCol] = 'S';
- hidden[shipStartRow - 2][shipStartCol] = 'S';
- } else /*if (shipStartRow < 2)*/ {
- hidden[shipStartRow][shipStartCol] = 'S';
- hidden[shipStartRow + 1][shipStartCol] = 'S';
- hidden[shipStartRow + 2][shipStartCol] = 'S';
- }
- }
- }
- public static void play(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement