Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions exercise.main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ namespace exercise.main
{
public class Core
{


Dictionary<string, int> cardValue = new Dictionary<string, int>() {
{"2", 2}, {"3", 3}, {"4", 4}, {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8},
{ "9", 9}, { "10", 10}, { "J", 11}, {"Q", 12}, {"K", 13}, {"A", 14}
};

//TODO: complete the following method, keeping the signature the same
public bool winningPair(IEnumerable<Tuple<string, string>> hand, out Tuple<string, string> result)
{
Expand All @@ -20,13 +23,12 @@ public bool winningPair(IEnumerable<Tuple<string, string>> hand, out Tuple<strin





return result.Item1!=string.Empty ? true : false;
}
public int GetValueOfCard(string card)
{
return 0;
cardValue.TryGetValue(card, out int value);
return (value >= 0) ? value : 0;
}
}
}
42 changes: 42 additions & 0 deletions exercise.main/Objects/Card.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main.Objects
{
public class Card
{
string[] _suitsSymbol = new string[8] { "♠", "♥", "♦", "♣", "♤", "♡", "♢", "♧" };
string[] _valueSymbol = new string[4] { "J", "Q", "K", "A"};

// Tuple contains value and suit
Tuple<int, int> _cardInfo;


public Card(int val, int suit)
{
_cardInfo = Tuple.Create(val, suit);
}


public string ValueSymbol {
get
{
int value = _cardInfo.Item1;
//"11j 12q 13k 14A"
if (value > 14 || value < 2)
return "?";

if(value <= 10)
return value.ToString();

return _valueSymbol[value - 11];
}
}
public int Value { get => _cardInfo.Item1; }
public string Suit { get => _suitsSymbol[_cardInfo.Item2]; }
public int SuitID { get => _cardInfo.Item2; }
}
}
59 changes: 59 additions & 0 deletions exercise.main/Objects/Deck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using exercise.main.Objects;

namespace exercise.main
{
public class Deck
{
private List<Card> _cardsInDeck = new List<Card>();
private readonly Random _random = new Random();

public List<Card> CardsInDeck { get { return _cardsInDeck; } }

public Deck()
{
// Fill deck with cards
for(int val = 2; val <= 14; val++)
{
for(int suit = 0; suit < 8; suit++)
{
_cardsInDeck.Add(new Card(val, suit));
}
}
}

public void Shuffle()
{
_cardsInDeck = _cardsInDeck.OrderBy(card => _random.Next()).ToList();
}

public Card Deal()
{
if (_cardsInDeck.Count == 0)
return new Card(0,0);

// Get card on top of deck
Card cardToGive = _cardsInDeck.ElementAt(0);
_cardsInDeck.RemoveAt(0);

return cardToGive;
}
/*public void ShowCards()
{
foreach (Card card in _cardsInDeck)
{

Console.Write(card.ValueSymbol + card.Suit);

if (_cardsInDeck.Last() != card)
{
Console.Write(", ");
}
}
}*/
}
}
43 changes: 43 additions & 0 deletions exercise.main/Objects/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main.Objects
{
public class Player
{
private string _name = "Unknown";

private List<Card> _hand = new List<Card>();

public List<Card> CardsInHand { get { return _hand; } }

public Player(string name)
{
_name = name;
}

public void DrawCard(Card card)
{
_hand.Add(card);
}

public void ShowCards()
{
foreach(Card card in _hand)
{

Console.Write(card.ValueSymbol + card.Suit);

if (_hand.Last() != card)
{
Console.Write(", ");
}
}
}

public string Name { get => _name; }
}
}
Loading