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