Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class SeaBattle {
  5. public static void main(String[] args) {
  6. // ...x...
  7. char[] cells = new char[10];
  8.  
  9. for (int i = 0; i < cells.length; i++) {
  10. cells[i] = '.';
  11. }
  12. int position = 4;
  13. cells[position]='X';
  14. // for (char cell : cells) {
  15. // System.out.print(cell);
  16. // }
  17.  
  18. do {
  19. System.out.println(cells);
  20. Scanner scanner = new Scanner(System.in);
  21. String s = scanner.nextLine();
  22. System.out.printf("You have entered: %s\n", s);
  23.  
  24. int shoot = Integer.parseInt(s);
  25. switch (cells[shoot]) {
  26. case '.':
  27. System.out.println("Sosai!");
  28. cells[shoot] = '*';
  29. break;
  30. case 'X':
  31. System.out.println("Zbs, chetko!");
  32. cells[shoot] = 'O';
  33. System.out.println(cells);
  34. break;
  35. case '*':
  36. System.out.println("Уже стрелял!");
  37. break;
  38. default:
  39. System.out.println("Fatality");
  40. }
  41. } while (cells[position] == 'X');
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement