Advertisement
nikolapetkov824

P02Baking_Rush

Oct 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P02
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine()
  12.                 .Split('|')
  13.                 .ToList();
  14.  
  15.             int initialEnergy = 100;
  16.             int initialCoin = 100;
  17.             int currentEnergy = initialEnergy;
  18.             int currentCoin = initialCoin;
  19.  
  20.             for (int i = 0; i < input.Count; i++)
  21.             {
  22.  
  23.                 //string[] tokens = input[i].Split('-');
  24.                 List<string> token = input[i].Split('-').ToList();
  25.  
  26.  
  27.                 if (token[0] == "rest")
  28.                 {
  29.                     int number = int.Parse(token[1]);
  30.                     currentEnergy += number;
  31.                     if (currentEnergy >= initialEnergy)
  32.                     {
  33.                         currentEnergy = initialEnergy;
  34.                         Console.WriteLine($"You gained 0 energy.");
  35.                         Console.WriteLine($"Current energy: {currentEnergy}.");
  36.                     }
  37.                     else
  38.                     {
  39.                         Console.WriteLine($"You gained {number} energy.");
  40.                         Console.WriteLine($"Current energy: {currentEnergy}.");
  41.                     }
  42.                 }
  43.                 else if (token[0] == "order")
  44.                 {
  45.                     int coinsEarned = int.Parse(token[1]);
  46.                     currentEnergy -= 30;
  47.                     if (currentEnergy > 0)
  48.                     {
  49.                         currentCoin += coinsEarned;
  50.                         Console.WriteLine($"You earned {coinsEarned} coins.");
  51.                     }
  52.                     else if (currentEnergy < 0)
  53.                     {
  54.                         currentEnergy = 50;
  55.                         Console.WriteLine("You had to rest!");
  56.                         //continue;
  57.                     }
  58.                 }
  59.                 else
  60.                 {
  61.                     int calculation = int.Parse(token[1]);
  62.                     currentCoin = currentCoin - calculation;
  63.  
  64.                     if (currentCoin > 0)
  65.                     {
  66.                         Console.WriteLine($"You bought {token[0]}.");
  67.                     }
  68.                     else if (currentCoin <= 0)
  69.                     {
  70.                         Console.WriteLine($"Closed! Cannot afford {token[0]}.");
  71.                         return;
  72.                     }
  73.                 }
  74.  
  75.             }
  76.             if (currentCoin > 0)
  77.             {
  78.                 Console.WriteLine("Day completed!");
  79.                 Console.WriteLine($"Coins: {currentCoin}");
  80.                 Console.WriteLine($"Energy: {currentEnergy}");
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement