Hi there all,
I am trying to calculate the score value for each card.
What I have so far is a player, dealer and card class. Iv created a calculate class as to handle all the calculations and hand the score for each card back to the dealer or player class.
My theory is to send each card that is handed out to the calculate class, then check what card it is and then send the value for that specific card to the player class to increment the players score by the cards amount.
But now how do I check the card and give it a score ?
I hade this but its to messy
switch (newCard)
{
case "Spades2:"
case "Hearts2:"
case "Diamonds2:"
case "Clubs2:"
pScore = 2;
break;
}
And so on.
newCard = the card value coming in and pScore = player score.
Heads up : im still a junier so please no bashing me.
Thanks in advance.
EDIT :
This is the rest of my code as you guys can see what I have so far.
I know its a lot of code but please bear with me.
Card Class :
public static class Card
{
private static string[] Suite = new string[4] {"Clubs", "Hearts", "Spades", "Diamonds" };
private static string[] FaceValue = new string[13] {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
public static List<string> CreateDeck()
{
List<string> deckOfCards = new List<string>();
for (int s = 0; s < 4; s++ )
{
string sut = Suite[s];
for (int fV = 0; fV < 13; fV++)
{
string value = FaceValue[fV];
deckOfCards.Add(sut + value);
}
}
deckOfCards.Shuffle();
return deckOfCards;
}
public static void Shuffle<T>(this IList<T> list)
{
Random rng = new Random();
int n = list.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
I know that I should have used enume instead of an array.
Dealer Class :
class Dealer
{
private List<string> randomisedCards;
public Dealer()
{
randomisedCards = Card.CreateDeck();
}
public string dealCard()
{
string randCard = randomisedCards[0];
randomisedCards.RemoveAt(0);
return randCard;
}
}
I wanted to send the ranCard to the calculate class to calculate the score value for that card.
Calculate class :
class Calculate
{
private string newCard;
private int pScore;
private int dScore;
public Calculate(string card)
{
newCard = card;
}
public Calculate(int playerScore, int dealerScore)
{
pScore = playerScore;
dScore = dealerScore;
}
public void calculateScore()
{
switch (newCard)
{
case "Spades":
case "Hearts":
pScore = 11;
break;
}
}
}
Im receiving the random card in the first constructor and the player score in the second constructor so I can send the cards value to the player class.
Player class
class Player
{
private int newPlayerScore;
private int newPlayerWin;
private int newPlayerLosses;
private int newPlayerTies;
public Player()
{
newPlayerScore = 0;
newPlayerWin = 0;
newPlayerLosses = 0;
newPlayerTies = 0;
}
public int calcPlayerScore
{
get
{
return newPlayerScore;
}
set
{
newPlayerScore += value;
}
}
}
The calculate player score propertie will accumulate the players score.