Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P02
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine()
- .Split('|')
- .ToList();
- int initialEnergy = 100;
- int initialCoin = 100;
- int currentEnergy = initialEnergy;
- int currentCoin = initialCoin;
- for (int i = 0; i < input.Count; i++)
- {
- //string[] tokens = input[i].Split('-');
- List<string> token = input[i].Split('-').ToList();
- if (token[0] == "rest")
- {
- int number = int.Parse(token[1]);
- currentEnergy += number;
- if (currentEnergy >= initialEnergy)
- {
- currentEnergy = initialEnergy;
- Console.WriteLine($"You gained 0 energy.");
- Console.WriteLine($"Current energy: {currentEnergy}.");
- }
- else
- {
- Console.WriteLine($"You gained {number} energy.");
- Console.WriteLine($"Current energy: {currentEnergy}.");
- }
- }
- else if (token[0] == "order")
- {
- int coinsEarned = int.Parse(token[1]);
- currentEnergy -= 30;
- if (currentEnergy > 0)
- {
- currentCoin += coinsEarned;
- Console.WriteLine($"You earned {coinsEarned} coins.");
- }
- else if (currentEnergy < 0)
- {
- currentEnergy = 50;
- Console.WriteLine("You had to rest!");
- //continue;
- }
- }
- else
- {
- int calculation = int.Parse(token[1]);
- currentCoin = currentCoin - calculation;
- if (currentCoin > 0)
- {
- Console.WriteLine($"You bought {token[0]}.");
- }
- else if (currentCoin <= 0)
- {
- Console.WriteLine($"Closed! Cannot afford {token[0]}.");
- return;
- }
- }
- }
- if (currentCoin > 0)
- {
- Console.WriteLine("Day completed!");
- Console.WriteLine($"Coins: {currentCoin}");
- Console.WriteLine($"Energy: {currentEnergy}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement