I am currently building a card game and everything works fine when I write output to the console.
However, when I write to a file, the suit associated with each card becomes a strange set of 4 different characters. Instead of printing the Heart, Diamond, Club and Spade symbols as defined in an ASCII table, the file produces 4 different characters that include – and |. The other two characters look like tiny super-scripted L’s.
public enum SUIT { HEART = 0, DIAMOND = 1, CLUB = 2, SPADE = 3 };
public enum VALUE { NINE = 0, JACK = 1, QUEEN = 2, KING = 3, TEN = 4, ACE = 5 };
public static string printCard(PinochleCard theCard)
//This card game uses a set of 5 card denominations
{
string cardS = "";
switch (theCard.cardValue)
{
case VALUE.ACE:
cardS += 'A';
break;
case VALUE.TEN:
cardS += "10";
break;
case VALUE.KING:
cardS += 'K';
break;
case VALUE.QUEEN:
cardS += 'Q';
break;
case VALUE.JACK:
cardS += 'J';
break;
case VALUE.NINE:
cardS += '9';
break;
}
cardS += (char)(theCard.suit + 3); // +3 converts to heart, diamond, club, spade in
return cardS.PadRight(4); // the console but not for files
}
Next I call this function in a loop to print a users hand.
Thanks for all the help!
ASCII doesn’t include hearts, diamonds, clubs and spades. Any “ASCII table” which includes them is talking about a specific encoding which is possibly compatible with ASCII for the first 127 values (which are all that ASCII defines) but then goes its own way.
.NET uses Unicode for everything text-related; you should consult the Unicode code charts to find the characters you want – but then consider how you’re going to write them to a file (which encoding you’ll use, etc). Often console fonts don’t support everything within Unicode.