Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Classes
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = System.Text.Encoding.GetEncoding(1200);
- Console.InputEncoding = System.Text.Encoding.GetEncoding(1200);
- Table table = new Table();
- table.TransferCard();
- table.ShowPlayerHand();
- table.ShowCardDeck();
- }
- }
- class Table
- {
- private CardDeck _cardDeck = new CardDeck();
- private Player _player = new Player();
- public void TransferCard()
- {
- int countDeckCard = GetDesiredCardsCount();
- int maxCountDeckCard = _cardDeck.Count;
- if (countDeckCard <= maxCountDeckCard && countDeckCard > 0)
- {
- for (int i = 0; i < countDeckCard; i++)
- {
- _player.AddCard(_cardDeck.GiveCard());
- }
- }
- else
- {
- Console.WriteLine("Хотите слишком много");
- }
- }
- public void ShowPlayerHand()
- {
- _player.ShowAll();
- }
- public void ShowCardDeck()
- {
- _cardDeck.ShowAll();
- }
- private int GetDesiredCardsCount()
- {
- Console.Write("Сколько карт хотите взять? : ");
- int.TryParse(Console.ReadLine(), out int count);
- return count;
- }
- }
- class Player
- {
- private List<Card> _cards = new List<Card>();
- public void AddCard(Card card)
- {
- if (card != null)
- _cards.Add(card);
- }
- public void ShowAll()
- {
- Console.Write($"\nКарты у игрока: {_cards.Count}\n\n");
- foreach (Card card in _cards)
- {
- Console.ForegroundColor = card.Color;
- Console.Write($"{card.Suit}{card.Value} ");
- Console.ResetColor();
- }
- }
- }
- class CardDeck
- {
- private List<Card> _cards = new List<Card>();
- public CardDeck()
- {
- Create();
- Shaffle();
- }
- public int Count => _cards.Count;
- public void ShowAll()
- {
- int countLine = 4;
- int cardInLine = _cards.Count / countLine;
- int count = 0;
- Console.Write($"\n\nОставшиеся карты в колоде: {_cards.Count}\n\n");
- foreach (Card card in _cards)
- {
- if (count > cardInLine)
- {
- Console.WriteLine("\n");
- count = 0;
- }
- Console.ForegroundColor = card.Color;
- Console.Write($"{card.Suit}{card.Value} ");
- Console.ResetColor();
- count++;
- }
- Console.WriteLine("\n");
- }
- public Card GiveCard()
- {
- if (_cards.Count > 0)
- {
- Card card = _cards[0];
- _cards.RemoveAt(0);
- return card;
- }
- else
- {
- return null;
- }
- }
- private void Create()
- {
- string[] suit = { "\u2660", "\u2665", "\u2666", "\u2663" };
- string[] value = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k", "a" };
- for (int i = 0; i < suit.Length; i++)
- {
- ConsoleColor color;
- if (suit[i] == "\u2666" || suit[i] == "\u2665")
- color = ConsoleColor.DarkRed;
- else
- color = ConsoleColor.DarkCyan;
- for (int j = 0; j < value.Length; j++)
- {
- _cards.Add(new Card(suit[i], value[j], color));
- }
- }
- }
- private void Shaffle()
- {
- Random random = new Random();
- for (int i = _cards.Count - 1; i > 0; i--)
- {
- int randomIndex = random.Next(_cards.Count);
- Card tempValue = _cards[i];
- _cards[i] = _cards[randomIndex];
- _cards[randomIndex] = tempValue;
- }
- }
- }
- class Card
- {
- public Card(string suit, string value, ConsoleColor color)
- {
- Suit = suit;
- Value = value;
- Color = color;
- }
- public string Suit { get; private set; }
- public string Value { get; private set; }
- public ConsoleColor Color { get; private set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement