Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class SeaBattle {
- public static void main(String[] args) {
- // ...x...
- char[] cells = new char[10];
- for (int i = 0; i < cells.length; i++) {
- cells[i] = '.';
- }
- int position = 4;
- cells[position]='X';
- // for (char cell : cells) {
- // System.out.print(cell);
- // }
- do {
- System.out.println(cells);
- Scanner scanner = new Scanner(System.in);
- String s = scanner.nextLine();
- System.out.printf("You have entered: %s\n", s);
- int shoot = Integer.parseInt(s);
- switch (cells[shoot]) {
- case '.':
- System.out.println("Sosai!");
- cells[shoot] = '*';
- break;
- case 'X':
- System.out.println("Zbs, chetko!");
- cells[shoot] = 'O';
- System.out.println(cells);
- break;
- case '*':
- System.out.println("Уже стрелял!");
- break;
- default:
- System.out.println("Fatality");
- }
- } while (cells[position] == 'X');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement