Created
April 25, 2025 19:11
-
-
Save IozhikLI/fded74717681dbcbc0b81301404b8270 to your computer and use it in GitHub Desktop.
ДЗ: Колода карт
This file contains hidden or 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.ComponentModel; | |
using System.Runtime.CompilerServices; | |
using System.Security.Cryptography; | |
namespace junior | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Player nic = new Player(6, "Ник"); | |
Player alex = new Player(2,"Алекс"); | |
Croupier tom = new Croupier(nic); | |
tom.GiveCardsPlayer(); | |
nic.ShowCards(); | |
tom.CurrentPlayer = alex; | |
tom.GiveCardsPlayer(); | |
alex.ShowCards(); | |
tom.GiveCardsPlayer(nic); | |
nic.ShowCards(); | |
} | |
enum Denomination | |
{ | |
Шестёрка, | |
Семёрка, | |
Восьмёрка, | |
Девятка, | |
Десятка, | |
Валет, | |
Дама, | |
Король, | |
Туз | |
} | |
enum Suits | |
{ | |
Бубны, | |
Пики, | |
Треф, | |
Черви | |
} | |
class Croupier | |
{ | |
private Deck _deck; | |
public Croupier(Player player) | |
{ | |
_deck = new Deck(); | |
CurrentPlayer = player; | |
} | |
public Player CurrentPlayer { get; set; } | |
public void GiveCardsPlayer() | |
{ | |
List<Card> cards = new List<Card>(); | |
for (int number = 0; number < CurrentPlayer.DesiredCard; number++) | |
{ | |
cards.Add(_deck.TakeOutRandomCard()); | |
} | |
CurrentPlayer.TakeCards(cards); | |
} | |
public void GiveCardsPlayer(Player player) | |
{ | |
List<Card> cards = new List<Card>(); | |
for (int number = 0; number < player.DesiredCard; number++) | |
{ | |
cards.Add(_deck.TakeOutRandomCard()); | |
} | |
player.TakeCards(cards); | |
} | |
} | |
class Player | |
{ | |
private List<Card> _cards; | |
public Player(int desiredCard, string name) | |
{ | |
Name = name; | |
DesiredCard = desiredCard; | |
_cards = new List<Card>(); | |
} | |
public string Name { get; private set; } | |
public int DesiredCard { get; private set; } | |
public void TakeCards(List<Card> newCards) | |
{ | |
_cards.AddRange(newCards); | |
} | |
public void ShowCards() | |
{ | |
Console.WriteLine($"\nКарты у {Name}\n"); | |
foreach (Card card in _cards) | |
{ | |
card.ShowInfo(); | |
} | |
} | |
} | |
class Deck | |
{ | |
private static int s_numberDenomination; | |
private static int s_numberSuits; | |
private List<Card> _cards; | |
private Random _randomCard; | |
static Deck() | |
{ | |
s_numberDenomination = 9; | |
s_numberSuits = 4; | |
} | |
public Deck() | |
{ | |
_cards = new List<Card>(); | |
for (int denomination = 0; denomination < s_numberDenomination; denomination++) | |
{ | |
for (int suit = 0; suit < s_numberSuits; suit++) | |
{ | |
_cards.Add(new Card((Denomination)denomination, (Suits)suit)); | |
} | |
} | |
_randomCard = new Random(); | |
} | |
public Card TakeOutRandomCard() | |
{ | |
Card outcard; | |
int outIndex = _randomCard.Next(0, _cards.Count); | |
outcard = _cards[outIndex]; | |
_cards.RemoveAt(outIndex); | |
return outcard; | |
} | |
} | |
class Card | |
{ | |
public Card(Denomination denomination, Suits suit) | |
{ | |
Denomination = denomination; | |
Suit = suit; | |
} | |
private Denomination Denomination { get; set; } | |
private Suits Suit { get; set; } | |
public void ShowInfo() | |
{ | |
Console.WriteLine(Denomination + " " + Suit); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment