Example #1
0
  public void start() {
    int anzahlSchüsse = 0;
    boolean amLeben = true;
    Scanner sc = new Scanner(System.in);
    fillDotComCoords();
    dotComs.add(createDotCom());
    dotComs.add(createDotCom());
    dotComs.add(createDotCom());

    dotComs.get(0).setName("amazon.com");
    dotComs.get(1).setName("ebay.com");
    dotComs.get(2).setName("facebook.com");

    System.out.println("Willkommen zum DotCom-Versenken!");
    System.out.println(
        "Es wurden drei DotComs der größe drei auf einem 7x7 Raster verteilt(a0-g6)");
    while (amLeben) {
      updateDotComs();
      if (dotComs.isEmpty()) {
        amLeben = false;
      }
      System.out.println("Wohin willst du schießen?");
      String shootCoord = sc.nextLine();
      anzahlSchüsse++;
      for (DotCom dotCom : dotComs) {
        if (dotCom.treffer(shootCoord)) {
          System.out.println("Treffer!");

          if (dotCom.getOrte().isEmpty()) {
            System.out.println(dotCom.getName() + " wurde Versenkt!");
            deadDotComs.add(dotCom);
          }
        } else {
          System.out.println("Daneben!");
        }
      }
    }
    System.out.println(
        "Alle DotComs wurden versenkt! Gratulation! Du hast " + anzahlSchüsse + " gebraucht!");
    sc.close();
  }