Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trayforyou/ab93dd90b53f6af704ee52aa732ae8b2 to your computer and use it in GitHub Desktop.
Save trayforyou/ab93dd90b53f6af704ee52aa732ae8b2 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace OOP_number_4
{
internal class Program
{
static void Main(string[] args)
{
Croupier croupier = new Croupier();
Console.WriteLine("Сколько карт вы выдаете игроку:");
string inputUser = Console.ReadLine();
if (int.TryParse(inputUser, out int countOfCards))
{
croupier.DealCards(countOfCards);
croupier.ShowCardsOfPlayer();
Console.WriteLine("Попробовать еще раз...");
}
else
{
Console.WriteLine("Вы ввели что-то не так, игры не будет...");
}
Console.ReadKey();
Console.Clear();
}
}
class Croupier
{
private Player player = new Player();
private Deck deck = new Deck();
public void DealCards(int countOfCards)
{
player.GetCards(deck.GetSomeCardsFromDeck(countOfCards));
}
public void ShowCardsOfPlayer()
{
player.ShowCards();
}
}
class Card
{
private string _colour;
private string _art;
public Card(string colour, string art)
{
_colour = colour;
_art = art;
}
public void ShowInfo()
{
Console.Write($"Карта: {_colour} {_art}");
}
}
class Deck
{
private List<Card> _cards = new List<Card>();
private Random _random = new Random();
public Deck()
{
List<string> _colours = new List<string>();
List<string> _arts = new List<string>();
_colours.AddRange(new string[] { "Пики", "Червы", "Трефы", "Бубны" });
_arts.AddRange(new string[] { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Валет", "Дама", "Король", "Туз", });
foreach (string color in _colours)
{
foreach (string art in _arts)
{
_cards.Add(new Card(color, art));
}
}
}
public List<Card> GetSomeCardsFromDeck(int countOfCards)
{
List<Card> tempSomeCards = new List<Card>();
if (_cards.Count <= countOfCards)
{
Console.WriteLine("Столько карт у крупье нет, игрок не получит ни одной карты...");
return tempSomeCards;
}
for (int i = 0; i < countOfCards; i++)
{
int indexTargetCard = _random.Next(0, _cards.Count - 1);
tempSomeCards.Add(_cards[indexTargetCard]);
_cards.RemoveAt(indexTargetCard);
}
return tempSomeCards;
}
public void ShowAllCard()
{
Console.WriteLine("Все карты:");
foreach (Card card in _cards)
{
card.ShowInfo();
Console.WriteLine();
}
}
}
class Player
{
private List<Card> havingCards = new List<Card>();
public void GetCards(List<Card> tempCards)
{
havingCards = tempCards;
}
public void ShowCards()
{
Console.WriteLine("Карты игрока:");
foreach (Card card in havingCards)
{
card.ShowInfo();
Console.WriteLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment