Advertisement
nikolayneykov

Untitled

Mar 7th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P06_CardsGame
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int health = 100;
  12.             int treasure = 0;
  13.  
  14.             string[] dungeons = Console.ReadLine().Split("|").ToArray();
  15.  
  16.  
  17.             for (int i = 0; i < dungeons.Length; i++)
  18.             {
  19.  
  20.                 string[] tokens = dungeons[i].Split().ToArray();
  21.  
  22.                 if (tokens[0] == "potion")
  23.                 {
  24.                     int hp = int.Parse(tokens[1]);
  25.                     if (health + hp > 100)
  26.                     {
  27.  
  28.                         Console.WriteLine($"You healed for {100 - health} hp.");
  29.                         Console.WriteLine($"Current health: 100 hp.");
  30.                         health = 100;
  31.                     }
  32.                     else if (health + hp <= 100)
  33.                     {
  34.                         Console.WriteLine($"You healed for {hp} hp.");
  35.                         Console.WriteLine($"Current health: {health + hp} hp.");
  36.                         health += hp;//+
  37.                     }
  38.                 }
  39.                 if (tokens[0] == "chest")
  40.                 {
  41.                     int coins = int.Parse(tokens[1]);
  42.                     treasure += coins;
  43.                     Console.WriteLine($"You found {coins} coins.");
  44.                 }
  45.                 if (tokens[0] != "potion" && tokens[0] != "chest")
  46.                 {
  47.                     int monsterAttack = int.Parse(tokens[1]);
  48.                     health -= monsterAttack;
  49.                     if (health > 0)
  50.                     {
  51.  
  52.                         Console.WriteLine($"You slayed {tokens[0]}.");
  53.                     }
  54.                     if (health <= 0)
  55.                     {
  56.  
  57.                         Console.WriteLine($"You died! Killed by {tokens[0]}.");
  58.                         Console.WriteLine($"Best room: {i+1}");
  59.                         break;
  60.  
  61.                     }
  62.                 }
  63.  
  64.  
  65.  
  66.  
  67.             }
  68.  
  69.             if (health > 0)
  70.             {
  71.                 Console.WriteLine($"You've made it!");
  72.                 Console.WriteLine($"Coins: {treasure}");
  73.                 Console.WriteLine($"Health: {health}");
  74.             }
  75.  
  76.  
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement