Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class BattleShip {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enemy Warship spotted on the horizon.");
- String[] dots = new String[] { "~", "~", "~", "~", "~", "~", "~", "~", "~", "~", " ~", " ~", " ~", " ~", " ~", " ~", " ~", " ~", " ~", " ~"};
- Random r = new Random();
- int ship = r.nextInt(20);
- for (int HP = 10; HP >= 0; HP--) {
- for (int i = 0; i < dots.length; i++); {
- int i = 0;
- System.out.print(dots[i] + " ");
- }
- System.out.println();
- System.out.println("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19");
- System.out.println();
- System.out.println();
- System.out.println("Health: " + HP);
- System.out.println();
- System.out.println("Choose location to Attack!!: ");
- int attack = input.nextInt();
- if (attack == ship) {
- System.out.println("You Win");
- break;
- }else {
- dots[attack] = "X";
- if (HP == 0) {
- System.out.println("You Lose!!");
- }
- }}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement