Created
May 9, 2024 22:09
-
-
Save NoDamage111/1865787584a5eedf0787fd699a258234 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) | |
{ | |
CardDeck cardDeck = new CardDeck(); | |
Dealer dealer = new Dealer(cardDeck); | |
Player player = new Player(dealer); | |
dealer.ShaffleNewDeck(); | |
player.TakeCards(); | |
player.ShowCards(); | |
Console.ReadKey(); | |
} | |
} | |
class CardDeck | |
{ | |
public static int cardInDeck = 36; | |
private string[] _valueList = { "6", "7", "8", "9", "10", "валет", "дама", "король", "туз" }; | |
private string[] _suitList = { "пик", "бубей", "треф", "черви" }; | |
public List<Card> CreateNewDeck() | |
{ | |
List<Card> cards = new List<Card>(); | |
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); | |
} | |
} | |
return cards; | |
} | |
} | |
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> _newDeck = new List<Card>(); | |
public Dealer(CardDeck cardDeck) | |
{ | |
CardDeck = cardDeck; | |
} | |
public CardDeck CardDeck { get; private set; } | |
public void ShaffleNewDeck() | |
{ | |
Random random = new Random(); | |
int minValue = 0; | |
int maxValue = 1; | |
Card temp; | |
_newDeck = CardDeck.CreateNewDeck(); | |
for (int i = 0;i < _newDeck.Count; i++) | |
{ | |
for(int j = 0;j< _newDeck.Count-1; j++) | |
{ | |
if (random.Next(minValue, maxValue+1) > 0) | |
{ | |
temp = _newDeck[j + 1]; | |
_newDeck[j + 1] = _newDeck[j]; | |
_newDeck[j] = temp; | |
} | |
} | |
} | |
} | |
public void ShowCards() | |
{ | |
Console.WriteLine("Карты крупье:"); | |
if (_newDeck.Count>0) | |
{ | |
foreach (Card card in _newDeck) | |
{ | |
Console.Write(card.Value + " " + card.Suit + "||"); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("У крупье нет карт"); | |
} | |
} | |
public Card GiveCard() | |
{ | |
int i = CardDeck.cardInDeck-1; | |
Card currentCard = _newDeck[i]; | |
_newDeck.RemoveAt(i); | |
CardDeck.cardInDeck--; | |
return currentCard; | |
} | |
} | |
class Player | |
{ | |
private List<Card> _cardsInHands = new List<Card>(); | |
public Player(Dealer dealer) | |
{ | |
Dealer=dealer; | |
} | |
public Dealer Dealer { get; private set; } | |
public void TakeCards() | |
{ | |
Console.Write("Сколько карт Вам сдать?"); | |
string userInput = Console.ReadLine(); | |
if (int.TryParse(userInput,out int count)) | |
{ | |
if (count <0||count>36) | |
{ | |
Console.WriteLine("Я не могу Вам сдеть столько карт"); | |
} | |
else | |
{ | |
for (int i = 0; i < count; i++) | |
{ | |
Card currentCard = Dealer.GiveCard(); | |
_cardsInHands.Add(currentCard); | |
} | |
} | |
} | |
} | |
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