Advertisement
asvd32

cards

Jun 26th, 2022
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. // ЗД12 Бой с Боссом.
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5.  
  6. namespace ConsoleApp3
  7. {
  8.     internal class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Deck deck = new Deck();
  13.             deck.HandOutCards(10);
  14.         }
  15.     }
  16.     class Card
  17.     {
  18.         public string Name { get; private set; }
  19.         public string Suit { get; private set; }
  20.  
  21.         public Card( string name, string suit)
  22.         {
  23.             Name = name;
  24.             Suit = suit;        
  25.         }      
  26.     }
  27.  
  28.     class Deck
  29.     {
  30.         private int _size;
  31.         private List<Card> _deck;
  32.         private string[] _suits = { "Черва", "Крести", "Пика", "Бубна" };
  33.         private string[] _names = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Валет", "Дама", "Король", "Туз" };
  34.         private Random _random;
  35.  
  36.         public Deck()
  37.         {
  38.             _size = 56;
  39.             _deck = new List<Card>(_size);
  40.             MakeDeck();
  41.             _random = new Random();
  42.         }
  43.         private void MakeDeck()
  44.         {
  45.             for (int index = 0; index < _suits.Length; index++)
  46.             {
  47.                 for (int subIndex = 0; subIndex < _names.Length; subIndex++)
  48.                 {
  49.                     _deck.Add(new Card(_names[subIndex], _suits[index]));
  50.                 }
  51.             }
  52.         }
  53.         public void PrintDeck()
  54.         {
  55.             foreach (var elemet in _deck)
  56.             {
  57.                 Console.WriteLine(elemet.Name +" "+ elemet.Suit);
  58.             }
  59.         }
  60.         public void HandOutCards(int count)
  61.         {
  62.             for (int index = 0; index < count; index++)
  63.             {
  64.                 int card = _random.Next(0, _size);
  65.                 Console.WriteLine(_deck[card].Name +" "+ _deck[card].Suit);
  66.             }
  67.         }
  68.     }
  69. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement