The classes were given to us so they are all correct.
I am struggling with 2 parts.
1. searching for ace and asking if they want a 1 or 11
2. displaying the points of each hand
In the class the code for the cards facevalue is
public enum FaceValue {
Two , Three , Four , Five , Six , Seven , Eight ,
Nine , Ten , Jack , Queen , King , Ace
I know i need to give them a number value also.Below is the code that deals two cards to the player and dealer and shows them to the screen. However i think i need to implement a switch statement to make the facevalues return a number instead of a word.
can anyone advise how and where to do this.
public TwentyOne() {
hands[PLAYER] = new ArrayList();
hands[DEALER] = new ArrayList();
///
/// Plays Twenty-one
///
///
public void Play() {
pack.Shuffle();
hands[PLAYER].AddRange(pack.DealTwoCards());
hands[DEALER].AddRange(pack.DealTwoCards());
DisplayHand(hands[PLAYER], "Player");
DisplayHand(hands[DEALER], "Dealer");
i apologise if i have done something incorrectly as i am new to this forum.
Jean PaulPosted Oct 27, 2010, 4:50 AM
For getting the ordinal value of the enum you can use the code (no need of switch statement):
FaceValue fv = FaceValue.Three;
int value = Enum.GetNames(typeof(FaceValue)).ToList().IndexOf(fv.ToString());
// Here the ordinal position is automatically chosen - from 0, 1, 2 etc.