1st json over websocket test
This commit is contained in:
51
Mau/Card.cs
Normal file
51
Mau/Card.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace MauMau_Server.Mau;
|
||||
|
||||
public class Card
|
||||
{
|
||||
public readonly CardType CardType;
|
||||
public readonly CardValue CardValue;
|
||||
|
||||
public Card(CardType cardType, CardValue cardValue)
|
||||
{
|
||||
CardType = cardType;
|
||||
CardValue = cardValue;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{CardType} {CardValue}";
|
||||
}
|
||||
|
||||
public Card parseCard(string card)
|
||||
{
|
||||
var cardType = card.Split(" ")[0];
|
||||
var cardValue = card.Split(" ")[1];
|
||||
return new Card((CardType)Enum.Parse(typeof(CardType), cardType),
|
||||
(CardValue)Enum.Parse(typeof(CardValue), cardValue));
|
||||
}
|
||||
}
|
||||
|
||||
public enum CardType
|
||||
{
|
||||
SPADES,
|
||||
HEARTS,
|
||||
DIAMONDS,
|
||||
CLUBS
|
||||
}
|
||||
|
||||
public enum CardValue
|
||||
{
|
||||
TWO,
|
||||
THREE,
|
||||
FOUR,
|
||||
FIVE,
|
||||
SIX,
|
||||
SEVEN,
|
||||
EIGHT,
|
||||
NINE,
|
||||
TEN,
|
||||
JACK,
|
||||
QUEEN,
|
||||
KING,
|
||||
ACE
|
||||
}
|
||||
30
Mau/CardDTO.cs
Normal file
30
Mau/CardDTO.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace MauMau_Server.Mau;
|
||||
|
||||
public class CardDTO
|
||||
{
|
||||
public string CardType { get; set; }
|
||||
public string CardValue { get; set; }
|
||||
|
||||
public CardDTO(Card card)
|
||||
{
|
||||
CardType = card.CardType.ToString();
|
||||
CardValue = card.CardValue.ToString();
|
||||
}
|
||||
|
||||
public CardDTO(string cardType, string cardValue)
|
||||
{
|
||||
CardType = cardType;
|
||||
CardValue = cardValue;
|
||||
}
|
||||
|
||||
public CardDTO()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Card ToCard()
|
||||
{
|
||||
return new Card((CardType)Enum.Parse(typeof(CardType), CardType),
|
||||
(CardValue)Enum.Parse(typeof(CardValue), CardValue));
|
||||
}
|
||||
}
|
||||
40
Mau/Deck.cs
Normal file
40
Mau/Deck.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
namespace MauMau_Server.Mau;
|
||||
|
||||
public class Deck
|
||||
{
|
||||
public List<Card> UnusedDeck = new();
|
||||
|
||||
public Deck()
|
||||
{
|
||||
foreach (CardType cardType in Enum.GetValues(typeof(CardType)))
|
||||
{
|
||||
foreach (CardValue cardValue in Enum.GetValues(typeof(CardValue)))
|
||||
{
|
||||
UnusedDeck.Add(new Card(cardType, cardValue));
|
||||
}
|
||||
}
|
||||
UnusedDeck = UnusedDeck.OrderBy(x => Guid.NewGuid()).ToList();
|
||||
}
|
||||
|
||||
public List<Card> GetUnusedDeck()
|
||||
{
|
||||
return UnusedDeck;
|
||||
}
|
||||
|
||||
public Card DrawCard()
|
||||
{
|
||||
var card = UnusedDeck[0];
|
||||
UnusedDeck.RemoveAt(0);
|
||||
return card;
|
||||
}
|
||||
|
||||
public List<Card> DrawCards(int amount)
|
||||
{
|
||||
var cards = new List<Card>();
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
cards.Add(DrawCard());
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
}
|
||||
19
Mau/HandDTO.cs
Normal file
19
Mau/HandDTO.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace MauMau_Server.Mau;
|
||||
|
||||
public class HandDTO
|
||||
{
|
||||
public List<string> _cards { get; set; } = new();
|
||||
|
||||
public HandDTO(List<Card> cards)
|
||||
{
|
||||
foreach (var card in cards)
|
||||
{
|
||||
_cards.Add(card.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public HandDTO()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user