Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pr2DungeonestDark {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int healt = 100;
- String[] rooms = scanner.nextLine().split("\\|");
- int sumCoins = 0;
- int valueBestRoom = 0;
- int bestIndex = 0;
- int healed = 0;
- int spentHealt = 0;
- for (int i = 0; i < rooms.length; i++) {
- String[] command = rooms[i].split(" ");
- switch (command[0]) {
- case "potion":
- if (healt + Integer.parseInt(command[1]) > 100) {
- int tempHealt = healt;
- healt = 100;
- healed = healt - tempHealt;
- } else {
- healed = Integer.parseInt(command[1]);
- healt = healt + Integer.parseInt(command[1]);
- }
- System.out.println(String.format("You healed for %s hp.", healed));
- System.out.println(String.format("Current health: %d hp.", healt));
- break;
- case "chest":
- System.out.println(String.format("You found %s coins.", command[1]));
- sumCoins += Integer.parseInt(command[1]);
- break;
- default:
- if (Integer.parseInt(command[1]) > valueBestRoom) {
- valueBestRoom = Integer.parseInt(command[1]);
- bestIndex = i + 1;
- }
- if (healt > Integer.parseInt(command[1])) {//>=
- healt = healt - Integer.parseInt(command[1]);
- System.out.println(String.format("You slayed %s.", command[0]));
- spentHealt = spentHealt + Integer.parseInt(command[1]);
- } else {
- System.out.println(String.format("You died! Killed by %s.", command[0]));
- System.out.println(String.format("Best room: %d", bestIndex));
- return;
- }
- }
- }
- System.out.println(String.format("You've made it!%nCoins: %d%nHealth: %d", sumCoins, healt));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement