Skip to content

Instantly share code, notes, and snippets.

@IvanEnginer
Created September 1, 2024 15:13
Show Gist options
  • Save IvanEnginer/a8606b7d626daf602bf5116ebd454077 to your computer and use it in GitHub Desktop.
Save IvanEnginer/a8606b7d626daf602bf5116ebd454077 to your computer and use it in GitHub Desktop.
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;
int commandMakeCoin = 1;
int commandEsc = 2;
int commandPutCoin = 1;
int commandAbortCoin = 2;
Player player = new Player();
CoinsHolder coinsHolder = new CoinsHolder();
while (isWork)
{
Console.WriteLine($"Баланс игрока: {player.ShowBallanse()}");
Console.WriteLine($"Для генерации монеты введите {commandMakeCoin}, что бы завершить программу введите {commandEsc}.");
input = Console.ReadLine();
if(int.TryParse(input, out int commandGenerator))
{
if(commandGenerator == commandMakeCoin)
{
coinsHolder.MakeCoin();
}
else if(commandGenerator == commandEsc)
{
isWork = false;
break;
}
}
Console.WriteLine($"Что бы отдать игроку монету введите {commandPutCoin}, что бы выкинуть монетку введите {commandAbortCoin}");
input = Console.ReadLine();
if (int.TryParse(input, out int commandChoise))
{
if (commandChoise == commandPutCoin)
{
coinsHolder.DiliveryCoinToPlayer(player);
}
else if (commandChoise == commandAbortCoin)
{
coinsHolder.AborеCoin();
}
}
Console.Clear();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment