Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Alexoshurkovv/1acf8fc2a9ba0705ed33781fe383294b to your computer and use it in GitHub Desktop.
Save Alexoshurkovv/1acf8fc2a9ba0705ed33781fe383294b to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
GameBoard board = new GameBoard();
board.Run();
}
}
class Utils
{
public static int ReadInt()
{
bool isNumber = int.TryParse(Console.ReadLine(), out int number);
if (isNumber == false)
{
Console.Write("Это не число! Введите число: ");
number = ReadInt();
}
return number;
}
}
class Player
{
private List<Card> _cards;
public Player(int qualityCard, List<Card> cards)
{
QualityCards = qualityCard;
_cards = cards;
}
public int QualityCards { get; private set; }
public void WriteInfo()
{
Console.WriteLine("У вас есть данные карты: ");
int count = 0;
foreach (Card card in _cards)
{
Console.WriteLine($"{++count}. Значение: {card.Value} Масть: {card.Suit}.");
}
}
}
class Pack
{
private List<Card> _cards;
public Pack()
{
_cards = new List<Card>();
_cards = FillCards(_cards);
CountCards = _cards.Count;
}
public int CountCards { get; private set; }
public Card GetCard()
{
Card card = _cards.ElementAt(0);
_cards.RemoveAt(0);
return card;
}
public List<Card> FillCards(List<Card> cards)
{
Random random = new Random();
List<string> values = new List<string> {"6", "7", "8", "9", "10", "Валет", "Дама", "Король", "Туз" };
List<string> suits = new List<string> { "Черви", "Пики", "Бубны", "Трефы" };
for (int i = 0; i < values.Count; i++)
{
for (int j = 0; j < suits.Count; j++)
{
cards.Add(new Card(values[i], suits[j]));
}
}
for (int i = cards.Count-1;i >= 1; i--)
{
int index = random.Next(i + 1);
Card card = cards[index];
cards[index] = cards[i];
cards[i] = card;
}
return cards;
}
}
class Card
{
public Card(string value, string suit)
{
Value = value;
Suit = suit;
}
public string Value { get; private set; }
public string Suit { get; private set; }
}
class GameBoard
{
public GameBoard()
{
PackGame = new Pack();
}
public Player PlayerGame { get; private set; }
public Pack PackGame { get; private set; }
public bool TryGiveCard()
{
Console.Write("Введите кол-во карт которые вы хотите получить: ");
int quality = Utils.ReadInt();
if (quality > PackGame.CountCards)
{
Console.WriteLine("Данное количество больше чем в колоде");
return false;
}
else
{
List<Card> cards = new List<Card>();
int count = PackGame.CountCards - 1;
for (int i = 0; i < quality; i++)
{
Card card = PackGame.GetCard();
cards.Add(card);
count--;
}
PlayerGame = new Player(quality, cards);
return true;
}
}
public void Run()
{
bool isGiveCard = false;
while (isGiveCard == false)
{
isGiveCard = TryGiveCard();
}
PlayerGame.WriteInfo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment