LeRoY_Go

Untitled

Jul 23rd, 2022
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace C_Sharp_Junior
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             Player player = new Player();
  11.             ConsoleKeyInfo pressedButton;
  12.  
  13.             do
  14.             {
  15.                 Console.Clear();
  16.                 Console.Write("1 - Взять карту (Y - yes/N - no): ");
  17.                 pressedButton = Console.ReadKey();
  18.                 Console.WriteLine();
  19.                 if (pressedButton.Key == ConsoleKey.Y)
  20.                     player.TakeCard();
  21.                 else
  22.                     player.ShowAllPlayingCards();
  23.                 Console.WriteLine("Нажмите любую кнопку для продолжения или ESC для завершения работы");
  24.                 pressedButton = Console.ReadKey();
  25.             } while (pressedButton.Key != ConsoleKey.Escape);
  26.  
  27.             Console.WriteLine("ПОКА");
  28.         }
  29.     }
  30.  
  31.     class Player
  32.     {
  33.         private DeckCards _deckCards;
  34.  
  35.         public Player()
  36.         {
  37.             _deckCards = new DeckCards();
  38.         }
  39.  
  40.         public void TakeCard()
  41.         {
  42.             _deckCards.AddCardDeck();
  43.         }
  44.  
  45.         public void ShowAllPlayingCards()
  46.         {
  47.             _deckCards.ShowAllCards();
  48.         }
  49.     }
  50.  
  51.     class DeckCards
  52.     {
  53.         private List<Card> _cards;
  54.         private List<int> _valuesPossibleCard;
  55.         private Random _random;
  56.  
  57.         public DeckCards()
  58.         {
  59.             _cards = new List<Card>();
  60.             _valuesPossibleCard = new List<int> { 6, 7, 8, 9, 10, 11, 12 };
  61.             _random = new Random();
  62.         }
  63.  
  64.         public void ShowAllCards()
  65.         {
  66.             if (_cards.Count > 0)
  67.                 foreach (var card in _cards)
  68.                     card.ShowInfo();
  69.             else
  70.                 Console.WriteLine("Ваша колода пуста!");
  71.         }
  72.  
  73.         public void AddCardDeck()
  74.         {
  75.             if (_valuesPossibleCard.Count > 0)
  76.             {
  77.                 int maxSuit = 4;
  78.                 int indexPlayingCard = _random.Next(_valuesPossibleCard.Count);
  79.                 int number = _valuesPossibleCard[indexPlayingCard];
  80.                 _valuesPossibleCard.RemoveAt(indexPlayingCard);
  81.                 _cards.Add(new Card((CardSuit)_random.Next(maxSuit), number));
  82.             }
  83.             else
  84.                 Console.WriteLine("Больше карт брать нельзя");
  85.         }
  86.  
  87.         enum CardSuit
  88.         {
  89.             Пики,
  90.             Червы,
  91.             Бубны,
  92.             Трефы
  93.         }
  94.  
  95.         class Card
  96.         {
  97.             private CardSuit _cardSuit;
  98.             private int _number;
  99.  
  100.             public Card(CardSuit cardSuit, int number)
  101.             {
  102.                 _cardSuit = cardSuit;
  103.                 _number = number;
  104.             }
  105.  
  106.             public void ShowInfo() => Console.WriteLine($"Масть: {_cardSuit} | Значение карты: {_number}");
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment