veronikaaa86

15. Neighbour Wars

Jan 31st, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package ConditionalStattementsLoops;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.Console;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7.  
  8. public class P15_NeighboursWar {
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.         int peshosDamage = Integer.parseInt(reader.readLine());
  13.         int goshosDamage = Integer.parseInt(reader.readLine());
  14.  
  15.         int peshosHealth = 100;
  16.         int goshosHealth = 100;
  17.         int attackCounter = 0;
  18.  
  19.         boolean isAnyoneAlive = true;
  20.         String attackName = "";
  21.         String attacker = "";
  22.         String attacked = "";
  23.         int attackedHealth = 0;
  24.  
  25.  
  26.         while (isAnyoneAlive) {
  27.             attackCounter++;
  28.             if (attackCounter % 2 != 0) {
  29.                 goshosHealth -= peshosDamage;
  30.                 attackName = "Roundhouse kick";
  31.                 attacker = "Pesho";
  32.                 attacked = "Gosho";
  33.                 attackedHealth = goshosHealth;
  34.             } else {
  35.                 peshosHealth -= goshosDamage;
  36.                 attackName = "Thunderous fist";
  37.                 attacker = "Gosho";
  38.                 attacked = "Pesho";
  39.                 attackedHealth = peshosHealth;
  40.             }
  41.             if (peshosHealth <= 0 || goshosHealth <= 0)
  42.             {
  43.                 System.out.printf("%s won in %dth round.%n", attacker, attackCounter);
  44.                 isAnyoneAlive = false;
  45.             } else {
  46.                 if (attackCounter % 3 == 0) {
  47.                     goshosHealth += 10;
  48.                     peshosHealth += 10;
  49.                 }
  50.                 System.out.printf("%s used %s and reduced %s to %d health.%n",
  51.                         attacker, attackName, attacked, attackedHealth);
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment