Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExamTechNov42018;
- import java.util.Scanner;
- public class DungeonestDark {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String[] rooms = input.split("\\|");
- int initialHealth = 100;
- boolean isDead = false;
- int countRooms = 0;
- int coins = 0;
- for (int i = 0; i < rooms.length; i++) {
- countRooms++;
- String[] currentRoom = rooms[i].split(" ");
- int number = Integer.parseInt(currentRoom[1]);
- if (currentRoom[0].equals("chest")) {
- coins += number;
- System.out.println(String.format("You found %s coins.", currentRoom[1]));
- } else if (currentRoom[0].equals("potion")) {
- if (initialHealth == 100 || number <= 0) {
- System.out.println("You healed for 0 hp.");
- System.out.println(String.format("Current health: 100 hp."));
- } else if (100 - initialHealth <= number) {
- System.out.println(String.format("You healed for %d hp.", 100 - initialHealth));
- initialHealth = 100;
- System.out.println(String.format("Current health: %d hp.", initialHealth));
- } else {
- initialHealth += number;
- System.out.println(String.format("You healed for %d hp.", number));
- System.out.println(String.format("Current health: %d hp.", initialHealth));
- }
- } else {
- if (initialHealth <= number) {
- System.out.println(String.format("You died! Killed by %s.", currentRoom[0]));
- System.out.println(String.format("Best room: %d", countRooms));
- isDead = true;
- break;
- } else {
- initialHealth -= number;
- System.out.println(String.format("You slayed %s.", currentRoom[0]));
- }
- }
- }
- if (!isDead) {
- System.out.println("You've made it!");
- System.out.println(String.format("Coins: %d", coins));
- System.out.println(String.format("Health: %d", initialHealth));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement