Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class BattleShip {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner input = new Scanner(System.in);
  9.  
  10. System.out.println("Enemy Warship spotted on the horizon.");
  11. String[] dots = new String[] { "~", "~", "~", "~", "~", "~", "~", "~", "~", "~", " ~", " ~", " ~", " ~", " ~", " ~", " ~", " ~", " ~", " ~"};
  12.  
  13. Random r = new Random();
  14. int ship = r.nextInt(20);
  15.  
  16. for (int HP = 10; HP >= 0; HP--) {
  17. for (int i = 0; i < dots.length; i++); {
  18. int i = 0;
  19. System.out.print(dots[i] + " ");
  20. }
  21.  
  22. System.out.println();
  23. System.out.println("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19");
  24. System.out.println();
  25. System.out.println();
  26. System.out.println("Health: " + HP);
  27. System.out.println();
  28. System.out.println("Choose location to Attack!!: ");
  29. int attack = input.nextInt();
  30. if (attack == ship) {
  31. System.out.println("You Win");
  32. break;
  33. }else {
  34. dots[attack] = "X";
  35. if (HP == 0) {
  36. System.out.println("You Lose!!");
  37. }
  38. }}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement