Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam.O5;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class O2MuOnline {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int health = 100;
- int bitcoin = 0;
- int room = 0;
- List<String> test = Arrays.stream(scanner.nextLine().split("\\|")).
- map(String::toString).collect(Collectors.toList());
- while (room < test.size()) {
- String command = test.get(room).split("\\s+")[0];
- int number = Integer.parseInt(test.get(room).split("\\s+")[1]);
- if (command.equals("potion")) {
- if (health < 100) {
- int a = health;
- health += number;
- if (health > 100) {
- number = 100 - a;
- health = 100;
- }
- System.out.printf("You healed for %d hp.%n", number);
- System.out.printf("Current health: %d hp.%n", health);
- }
- } else if (command.equals("chest")) {
- bitcoin += number;
- System.out.printf("You found %d bitcoins.%n", number);
- } else {
- health -= number;
- if (health <= 0) {
- System.out.printf("You died! Killed by %s.%n", command);
- System.out.printf("Best room: %d", room + 1);
- return;
- } else {
- System.out.printf("You slayed %s.%n", command);
- }
- }
- room++;
- }
- System.out.printf("You've made it!%n" + "Bitcoins: %d%n" + "Health: %d", bitcoin, health);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment