Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ООП
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userInput;
- int cardsCount;
- bool correctImput = false;
- string[] newDeck = { "6♠", "7♠", "8♠", "9♠", "10♠", "В♠", "Д♠", "К♠", "Т♠",
- "6♥", "7♥", "8♥", "9♥", "10♥", "В♥", "Д♥", "К♥", "Т♥",
- "6♦", "7♦", "8♦", "9♦", "10♦", "В♦", "Д♦", "К♦", "Т♦",
- "6♣", "7♣", "8♣", "9♣", "10♣", "В♣", "Д♣", "К♣", "Т♣",};
- Deck deck = new Deck(new List<Card>());
- deck.CreateCards(newDeck);
- Player player = new Player(new List<Card>());
- while (correctImput == false)
- {
- Console.Clear();
- Console.Write("Введите кол-во карт, которое необходимо взять: ");
- userInput = Console.ReadLine();
- correctImput = int.TryParse(userInput, out cardsCount);
- if (correctImput && cardsCount > 0 && cardsCount <= deck.CardsCount())
- {
- for (int i = 0; i < cardsCount; i++)
- {
- player.TakeCard(deck.GiveRandomCard());
- }
- }
- else
- {
- correctImput = false;
- Console.WriteLine("Некорректный ввод!");
- Console.ReadKey();
- }
- }
- Console.Write("Ваши карты: ");
- player.ShowCards();
- Console.ReadKey();
- }
- }
- class Deck
- {
- private List<Card> _deck;
- public Deck(List<Card> cards)
- {
- _deck = cards;
- }
- public void CreateCards(string[] cards)
- {
- foreach (var card in cards)
- {
- _deck.Add(new Card(card));
- }
- }
- public Card GiveRandomCard()
- {
- Random random = new Random();
- int index = random.Next(_deck.Count - 1);
- Card card = _deck[index];
- _deck.RemoveAt(index);
- return card;
- }
- public int CardsCount()
- {
- return _deck.Count;
- }
- }
- class Card
- {
- private string _cardName;
- public Card(string cardName)
- {
- _cardName = cardName;
- }
- public void ShowCard()
- {
- Console.Write(_cardName);
- }
- }
- class Player
- {
- private List<Card> _deck;
- public Player(List<Card> cards)
- {
- _deck = cards;
- }
- public void TakeCard(Card cardName)
- {
- _deck.Add(cardName);
- }
- public void ShowCards()
- {
- foreach (var card in _deck)
- {
- card.ShowCard();
- Console.Write(" ");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment