Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam;
- import java.util.Scanner;
- public class Second {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split("\\|+");
- int health = 100;
- int coins = 0;
- int roomCount = 0;
- for (String var : input) {
- String[] currentJob = var.split("\\s+");
- roomCount++;
- switch (currentJob[0]) {
- case "potion":
- if (health + Integer.parseInt(currentJob[1]) <= 100) {
- System.out.printf("You healed for %d hp.%n", Integer.parseInt(currentJob[1]));
- health += Integer.parseInt(currentJob[1]);
- } else if (health + Integer.parseInt(currentJob[1]) > 100) {
- int gainEnergy = 100 - health;
- System.out.printf("You healed for %d hp.%n", gainEnergy);
- health = 100;
- }
- System.out.printf("Current health: %d hp.%n", health);
- break;
- case "chest":
- coins += Integer.parseInt(currentJob[1]);
- System.out.printf("You found %s coins.%n", currentJob[1]);
- break;
- default:
- if (health - Integer.parseInt(currentJob[1]) > 0) {
- System.out.printf("You slayed %s.%n", currentJob[0]);
- health -= Integer.parseInt(currentJob[1]);
- } else {
- int temp = roomCount;
- System.out.printf("You died! Killed by %s.%n", currentJob[0]);
- System.out.printf("Best room: %d", temp);
- return;
- }
- }
- }
- System.out.printf("You've made it!%n");
- System.out.printf("Coins: %d%n", coins);
- System.out.printf("Health: %d%n", health);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement