Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam29022020;
- import java.util.Scanner;
- public class MuOnline {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int health = 100;
- int bitcoin = 0;
- boolean isDead = false;
- String [] rooms = sc.nextLine().split("\\|");
- for (int i = 0; i < rooms.length ; i++) {
- String [] command = rooms[i].split(" ");
- if("potion".equals(command[0])){
- int addHelth = Integer.parseInt(command[1]);
- if(health + addHelth <=100){
- health+=addHelth;
- }else {
- addHelth = 100 - health;
- health+=addHelth;
- }
- System.out.printf("You healed for %d hp.%n", addHelth);
- System.out.printf("Current health: %d hp.%n",health);
- }else if("chest".equals(command[0])){
- int foundBitcoin = Integer.parseInt(command[1]);
- System.out.printf("You found %d bitcoins.%n",foundBitcoin);
- bitcoin+=foundBitcoin;
- }else{
- int loseHelth = Integer.parseInt(command[1]);
- String monster = command[0];
- health-=loseHelth;
- if(health >0){
- System.out.printf("You slayed %s.%n",monster);
- }else{
- System.out.printf("You died! Killed by %s.%n", monster);
- System.out.printf("Best room: %d%n", i+1);
- isDead = true;
- break;
- }
- }
- }
- if(!isDead){
- System.out.printf("You've made it!%nBitcoins: %d%nHealth: %d%n", bitcoin, health);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement