Created
September 1, 2024 14:01
-
-
Save IvanEnginer/43968638eff9e437f1326b5b38f0d51c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace HW_03 | |
{ | |
class Player | |
{ | |
private Wallet _wallet = new Wallet(); | |
public void PutCoinToWallet(Coin coin) | |
{ | |
_wallet.AddCoin(coin); | |
} | |
public int ShowBallanse() | |
{ | |
return _wallet.ShowBallance(); | |
} | |
} | |
class CoinsGenerator | |
{ | |
private int minCoinValue = 1; | |
private int maxCoinValue = 101; | |
private Random _random = new Random(); | |
public Coin Generat() | |
{ | |
return new Coin(_random.Next(minCoinValue, maxCoinValue)); | |
} | |
} | |
class CoinsHolder | |
{ | |
private CoinsGenerator _coinsGenerator = new CoinsGenerator(); | |
private Coin _coin; | |
public void MakeCoin() | |
{ | |
_coin = _coinsGenerator.Generat(); | |
} | |
public void DiliveryCoinToPlayer(Player player) | |
{ | |
player.PutCoinToWallet(_coin); | |
} | |
public void AborеCoin() | |
{ | |
_coin = null; | |
} | |
} | |
class Wallet | |
{ | |
private List<Coin> _coins = new List<Coin>(); | |
public void AddCoin(Coin coin) | |
{ | |
_coins.Add(coin); | |
} | |
public int ShowBallance() | |
{ | |
int totale = 0; | |
for (int i = 0; i < _coins.Count; i++) | |
{ | |
totale += _coins[i].Value; | |
} | |
return totale; | |
} | |
} | |
class Coin | |
{ | |
public int Value { get; private set; } | |
public Coin(int value) | |
{ | |
Value = value; | |
} | |
} | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
bool isWork = true; | |
string input; | |
Player player = new Player(); | |
CoinsHolder coinsHolder = new CoinsHolder(); | |
while (isWork) | |
{ | |
Console.WriteLine($"Баланс игрока: {player.ShowBallanse()}"); | |
Console.WriteLine("Для генерации монеты введите 1, что бы завершить программу введите 2."); | |
input = Console.ReadLine(); | |
if(int.TryParse(input, out int commandGenerator)) | |
{ | |
if(commandGenerator == 1) | |
{ | |
coinsHolder.MakeCoin(); | |
} | |
else if(commandGenerator == 2) | |
{ | |
isWork = false; | |
break; | |
} | |
} | |
Console.WriteLine("Что бы отдать игроку монету введите 1, что бы выкинуть монетку введите 2"); | |
input = Console.ReadLine(); | |
if (int.TryParse(input, out int commandChoise)) | |
{ | |
if (commandChoise == 1) | |
{ | |
coinsHolder.DiliveryCoinToPlayer(player); | |
} | |
else if (commandChoise == 2) | |
{ | |
coinsHolder.AborеCoin(); | |
} | |
} | |
Console.Clear(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment