private void checkUserGuess(String userGuess) { numOfGuesses++; String result = "miss"; for (DotCom dotComToTest : dotComsList) { result = dotComToTest.checkYourself(userGuess); if (result.equals("hit")) { break; } if (result.equals("kill")) { dotComsList.remove(dotComToTest); break; } } System.out.println(result); }
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(); }
private void setUpGame() { DotCom one = new DotCom(); one.setName("Pets.com"); DotCom two = new DotCom(); two.setName("eToys.com"); DotCom three = new DotCom(); three.setName("Go2.com"); dotComsList.add(one); dotComsList.add(two); dotComsList.add(three); System.out.println("Your goal is to sink three dot coms."); System.out.println("Pets.com, eToys.com, Go2.com"); System.out.println("Try to sink them all in the fewest number of guesses"); for (DotCom dotComSet : dotComsList) { ArrayList<String> newLocation = helper.placeDotCom(3); dotComSet.setLocationCells(newLocation); } }