alexbancheva

Mu_Online_MidExam

Mar 2nd, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Mu_Online_MidExam
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             double health = 100;
  11.             double bitcoins = 0;
  12.             int room = 0;
  13.             double totalBitcoins = 0;
  14.  
  15.             var dungeousRooms = Console.ReadLine()
  16.                 .Split("|");
  17.             bool isVictory = false;
  18.  
  19.             for (int i = 0; i < dungeousRooms.Length; i++)
  20.             {
  21.                 var commandSec = dungeousRooms[i].Split(" ");
  22.                 string commandMain = commandSec[0];
  23.                 room++;
  24.                 if (commandMain == "potion")
  25.                 {
  26.                     int helpHealth = int.Parse(commandSec[1]);
  27.                    
  28.  
  29.                     if (health < 100)
  30.                     {
  31.                         if ((helpHealth + health) == 100)
  32.                         {
  33.                             Console.WriteLine($"You healed for {health} hp.");
  34.                         }
  35.                         else
  36.                         {
  37.                             double neededHealth = 100 - health;
  38.                             double noNeedHealth = Math.Abs(neededHealth - helpHealth);
  39.  
  40.                             health += neededHealth;
  41.                             Console.WriteLine($"You healed for {neededHealth} hp.");
  42.                         }
  43.                        
  44.                     }
  45.                     //else
  46.                     //{
  47.                     //    double diff = health - 100;
  48.                     //    double diffTwo = diff - helpHealth;
  49.                     //    Console.WriteLine($"You healed for {Math.Abs(diffTwo)} hp.");
  50.  
  51.                     //}
  52.                    
  53.                     Console.WriteLine($"Current health: {health} hp.");
  54.                     isVictory = true;
  55.  
  56.                 }
  57.                 else if (commandMain == "chest")
  58.                 {
  59.                     double amountBitcoins = int.Parse(commandSec[1]);
  60.                     Console.WriteLine($"You found {amountBitcoins} bitcoins.");
  61.                     totalBitcoins += amountBitcoins;
  62.                     isVictory = true;
  63.                 }
  64.                 else
  65.                 {
  66.                     double fightAttack = double.Parse(commandSec[1]);
  67.  
  68.                     health -= fightAttack;
  69.  
  70.                     if (health > 0 )
  71.                     {
  72.                         Console.WriteLine($"You slayed {commandMain}.");
  73.                         //continue;
  74.                     }
  75.                     else
  76.                     {
  77.                         Console.WriteLine($"You died! Killed by {commandMain}.");
  78.                         Console.WriteLine($"Best room: {room}");
  79.                         isVictory = false;
  80.                         break;
  81.                     }
  82.                 }
  83.  
  84.             }
  85.  
  86.             if (isVictory)
  87.             {
  88.                 Console.WriteLine("You've made it!");
  89.                 Console.WriteLine($"Bitcoins: {totalBitcoins}");
  90.                 Console.WriteLine($"Health: {health}");
  91.             }
  92.            
  93.  
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment