Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Test;
- import java.util.Scanner;
- public class Second {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String[] rooms = scan.nextLine().split("\\|");
- int health = 100;
- int bitcoin = 0;
- int bestRoom = 0;
- for (int i = 0; i < rooms.length; i++) {
- String[] tokens = rooms[i].split(" ");
- int command = Integer.parseInt(tokens[1]);
- if (tokens[0].equals("potion")){
- if (health + command <= 100){
- health += command;
- System.out.printf("You healed for %d hp.%n", command);
- System.out.printf("Current health: %d hp.%n", health);
- }else if (health + command > 100){
- int atFirst = health;
- health = 100;
- System.out.printf("You healed for %d hp.%n",100 - atFirst);
- System.out.printf("Current health: %d hp.%n", health);
- }
- }else if (tokens[0].equals("chest")){
- bitcoin += command;
- System.out.printf("You found %d bitcoins.%n", command);
- } else {
- if (health - command > 0){
- System.out.printf("You slew %s.%n", tokens[0]);
- health -= command;
- }else if (health - command <= 0){
- health -= command;
- System.out.printf("You died! Killed by %s.%n", tokens[0]);
- bestRoom++;
- System.out.printf("Best room: %d", bestRoom);
- break;
- }
- }
- bestRoom++;
- }
- if (health > 0){
- System.out.println("You've made it!");
- System.out.printf("Bitcoins: %d%n", bitcoin);
- System.out.printf("Health: %d%n", health);
- }
- }
- }
Add Comment
Please, Sign In to add comment