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 Clight_55_DeckOfCards
- {
- class Program
- {
- static void Main(string[] args)
- {
- char[] suits = new char[4] { '@', '#', '$', '&' };
- int[] nomanals = new int[] { 1, 2, 3, 4, 5, };
- bool isWorks = true;
- Player player = new Player("Bot");
- Random random = new Random();
- while (isWorks)
- {
- Console.CursorVisible = false;
- Console.Clear();
- Console.Write($"Колода игрока {player.Name}: ");
- player.ShowDeck();
- Console.WriteLine("\n");
- Console.WriteLine("F1 - Взять карту.");
- Console.WriteLine("F2 - Остановиться.");
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.F1:
- TakeCard(player, suits, nomanals, random);
- break;
- case ConsoleKey.F2:
- isWorks = false;
- break;
- default:
- break;
- }
- }
- Console.Clear();
- Console.Write($"Итоговая колода игрока {player.Name}: ");
- player.ShowDeck();
- Console.ReadKey();
- }
- public static void TakeCard(Player player, char[] suits, int[] nomanals, Random random)
- {
- Card tempCard = GetRandomCart(suits, nomanals, random);
- player.AddCart(tempCard);
- Console.Write("\nВыпала карта: ");
- tempCard.ShowCard();
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("\n\nДля продолжения нажмите любую клавишу.");
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.ReadKey();
- }
- public static Card GetRandomCart(char[] suits, int[] nomanals, Random random)
- {
- int numberSuit = random.Next(0, suits.Length);
- int numberNomanal = random.Next(0, nomanals.Length);
- Card card = new Card(suits[numberSuit], nomanals[numberNomanal]);
- return card;
- }
- public class Player
- {
- private Deck _deck;
- public string Name { get; private set; }
- public Player(string name)
- {
- Name = name;
- _deck = new Deck();
- }
- public void AddCart(Card card)
- {
- _deck.AddCart(card);
- }
- public void ShowDeck()
- {
- _deck.ShowDeck();
- }
- }
- public class Deck
- {
- private Card[] _cards;
- private Card[] _tempCards;
- public Deck()
- {
- _cards = new Card[0];
- }
- public void AddCart(Card card)
- {
- _tempCards = new Card[_cards.Length + 1];
- _cards.CopyTo(_tempCards, 0);
- _tempCards[_tempCards.Length - 1] = card;
- _cards = new Card[_tempCards.Length];
- _tempCards.CopyTo(_cards, 0);
- }
- public void ShowDeck()
- {
- foreach (var card in _cards)
- {
- card.ShowCard();
- Console.Write(" ");
- }
- }
- }
- public class Card
- {
- private char _suit;
- private int _nomanal;
- public Card(char suit, int nomanal)
- {
- _suit = suit;
- _nomanal = nomanal;
- }
- public void ShowCard()
- {
- Console.Write("{0}-{1}", _suit, _nomanal);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment