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 CSTemp
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int cardsInDeck = 36;
- Player player = new Player();
- Deck superheroDeck = new Deck(cardsInDeck);
- player.TakeCards(superheroDeck);
- Console.ReadKey();
- }
- }
- enum Superheroes
- {
- Batman,
- Spiderman,
- Thor,
- Hulk,
- Wolverine,
- Ironman
- }
- class Player
- {
- private List<Card> _takenCards = new List<Card>();
- public void TakeCards(Deck deck)
- {
- int amount = 0;
- bool correct = false;
- while (correct == false)
- {
- Console.Write("Сколько карт вы хотите взять: ");
- string userInput = Console.ReadLine();
- if (int.TryParse(userInput, out int result))
- {
- if (result <= deck.GetLenght())
- {
- amount = result;
- correct = true;
- }
- else
- {
- Console.WriteLine("В колоде меньше карт, введите другое число.");
- }
- }
- else
- {
- Console.WriteLine("Вы ввели не число.");
- }
- }
- for (int i = 0; i < amount; i++)
- {
- _takenCards.Add(deck.Pop());
- }
- Console.WriteLine("Вы взяли:");
- foreach (var card in _takenCards)
- {
- Console.WriteLine(card.Superhero);
- }
- }
- }
- class Deck
- {
- private Stack<Card> _cards = new Stack<Card>();
- private Random _random = new Random();
- public Deck(int number)
- {
- for (int i = 0; i < number; i++)
- {
- _cards.Push(new Card(_random.Next(0, Enum.GetNames(typeof(Superheroes)).Length)));
- }
- }
- public int GetLenght()
- {
- return _cards.Count;
- }
- public Card Pop()
- {
- return _cards.Pop();
- }
- }
- class Card
- {
- public Superheroes Superhero { get; private set; }
- public Card(int number)
- {
- Superhero = (Superheroes)number;
- }
- }
- }
Add Comment
Please, Sign In to add comment