Created
May 10, 2024 07:09
-
-
Save NoDamage111/9ae968f23b8fdb6c665166d6368497d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace ConsoleApp33 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Dealer dealer = new Dealer(); | |
dealer.GiveCard(); | |
dealer.ShowPlayerCard(); | |
Console.ReadKey(); | |
} | |
} | |
class CardDeck | |
{ | |
private List<Card> _deck = new List<Card>(); | |
public int Count { get; private set; } | |
public CardDeck() | |
{ | |
_deck = Create(); | |
Count = _deck.Count; | |
} | |
public List<Card> Create() | |
{ | |
Random random = new Random(); | |
int minValue = 0; | |
int maxValue = 1; | |
Card temp; | |
List<Card> cards = new List<Card>(); | |
string[] _valueList = { "6", "7", "8", "9", "10", "валет", "дама", "король", "туз" }; | |
string[] _suitList = { "пик", "бубей", "треф", "черви" }; | |
for (int i = 0; i < _suitList.Length; i++) | |
{ | |
for (int j = 0; j < _valueList.Length; j++) | |
{ | |
Card newCard = new Card(_valueList[j], _suitList[i]); | |
cards.Add(newCard); | |
} | |
} | |
for (int i = 0; i < cards.Count; i++) | |
{ | |
for (int j = 0; j < cards.Count - 1; j++) | |
{ | |
if (random.Next(minValue, maxValue + 1) > 0) | |
{ | |
temp = cards[j + 1]; | |
cards[j + 1] = cards[j]; | |
cards[j] = temp; | |
} | |
} | |
} | |
return cards; | |
} | |
public Card GiveCard() | |
{ | |
int i = _deck.Count - 1; | |
Card currentCard = _deck[i]; | |
_deck.RemoveAt(i); | |
return currentCard; | |
} | |
} | |
class Card | |
{ | |
public Card(string value, string suit) | |
{ | |
Value = value; | |
Suit = suit; | |
} | |
public string Value { get; private set; } | |
public string Suit { get; private set;} | |
} | |
class Dealer | |
{ | |
private List<Card> _deck = new List<Card>(); | |
private CardDeck _cardDeck = new CardDeck(); | |
private Player _player = new Player(); | |
public Dealer() | |
{ | |
_deck = _cardDeck.Create(); | |
} | |
public void ShowCards() | |
{ | |
Console.WriteLine("Карты крупье:"); | |
if (_deck.Count>0) | |
{ | |
foreach (Card card in _deck) | |
{ | |
Console.Write(card.Value + " " + card.Suit + "||"); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("У крупье нет карт"); | |
} | |
} | |
public void GiveCard() | |
{ | |
_cardDeck.GiveCard(); | |
_player.TakeCards(_cardDeck); | |
} | |
public void ShowPlayerCard() | |
{ | |
_player.ShowCards(); | |
} | |
} | |
class Player | |
{ | |
private List<Card> _cardsInHands = new List<Card>(); | |
public void TakeCards(CardDeck dealerCards) | |
{ | |
Console.Write("Сколько карт Вам сдать?"); | |
string userInput = Console.ReadLine(); | |
if (int.TryParse(userInput,out int count)) | |
{ | |
if (count <0||count> dealerCards.Count) | |
{ | |
Console.WriteLine("Я не могу Вам сдеть столько карт"); | |
} | |
else | |
{ | |
for (int i = 0; i < count; i++) | |
{ | |
Card currentCard = dealerCards.GiveCard(); | |
_cardsInHands.Add(currentCard); | |
} | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Неверный ввод"); | |
} | |
} | |
public void ShowCards() | |
{ | |
Console.WriteLine("\nКарты игрока:"); | |
if (_cardsInHands.Count > 0) | |
{ | |
foreach (Card card in _cardsInHands) | |
{ | |
Console.Write(card.Value + " " + card.Suit + "||"); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("У игрока нет карт"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment