package com.company;


import java.io.*;
import java.util.ArrayList;

public class DotCom {

    private ArrayList<String> locationCells;

    public void setLocationCells(ArrayList<String> loc) {

        locationCells = loc;
    }

    public String checkYourself(String userInput) {

        String result = "Мимо";

        int index = locationCells.indexOf(userInput);

        if(index>=0){
            locationCells.remove(index);

            if(locationCells.isEmpty()){
                result = "Потопил";
            }else{
                result = "Попал";
            }
        }
        return result;
    }

}
    public static void main(String[] args) {

        int numOfGuesses = 0;

        GameHelper helper = new GameHelper();
        DotCom theDotCom = new DotCom();

        int randomNum = (int) (Math.random() * 5);
        int[] locations = {randomNum, randomNum+1, randomNum+2};

        theDotCom.setLocationCells(locations);

        boolean isAlive = true;
        while (isAlive == true) {
            String guess = helper.getUserInput("Введите число");
            String result = theDotCom.checkYourself(guess);
            numOfGuesses++;
            if (result.equals("Потопил")) {
                isAlive = false;
                System.out.println("Вам потребовалось " + numOfGuesses + "попыток(и)");
            }
        }
    }
     public class GameHelper {
        public String getUserInput(String prompt) {
            String inputLine = null;
            System.out.println(prompt + " ");
            try {
                BufferedReader is = new BufferedReader
                        (new InputStreamReader(System.in));
                inputLine = is.readLine();
                if (inputLine.length() == 0)
                    return null;
            } catch (IOException e) {
                System.out.println("IOException " + e);
            }
            return inputLine;
    }
}