using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A5_Headless_Game { class Program { static void Main(string[] args) { // create a new game and start it Game game = new Game(); game.Play(); Console.WriteLine(game); } } public class Card { public readonly static char[] SUITS = new char[] { 'S', 'H', 'D', 'C' }; public Card(int value, char suit) { Value = value; Suit = suit; } public override bool Equals(object other) { Card other_card = other as Card; return Value == other_card.Value && Suit == other_card.Suit; } public override string ToString() { if (Value == 0) { // joker return "JJ"; } else if (Value == 1) { // ace return String.Format("A{0}", Suit); } else if (Value == 13) { // king return String.Format("K{0}", Suit); } else if (Value == 12) { // king return String.Format("Q{0}", Suit); } else if (Value == 11) { // king return String.Format("J{0}", Suit); } else if (Value == 10) { // 10 (to keep everything 2 chars) return String.Format("T{0}", Suit); } // 2-9 return String.Format("{0}{1}", Value, Suit); } public int Score() { if (Value == 0) { // joker return -2; } else if (Value == 1) { // ace return 1; } else if (Value == 13) { // king return 0; } return Value; } public int Value { get; set; } public char Suit { get; set; } } public class Deck { private static Random rand = new Random(); private List deck; public Deck(Deck other) { deck = new List(other.deck); } public Deck(int decks) { deck = new List(); // add the specified number of decks, in standard order for (int i = 0; i < decks; i++) { for (int j = 0; j < decks; j++) { // jokers on top deck.Add(new Card(0, 'J')); deck.Add(new Card(0, 'J')); // each suit, in order foreach (char suit in Card.SUITS) { // add ace first, then K-2 in order deck.Add(new Card(1, suit)); for (int k = 13; k > 1; k--) { deck.Add(new Card(k, suit)); } } } } } public void Shuffle() { for (int i = deck.Count - 1; i > 0; i--) { int swap = rand.Next(0, i); Card temp = deck[i]; deck[i] = deck[swap]; deck[swap] = temp; } } public Card Draw() { if (deck.Count == 0) { return null; } Card top = deck[0]; deck.RemoveAt(0); return top; } public Card Peek(int position) { if (position < deck.Count) { return deck[position]; } return null; } public void Add(Card newcard) { deck.Insert(0, newcard); } public int Length() { return deck.Count; } public override string ToString() { string ds = ""; int ct = 0; foreach (Card c in deck) { ds += c; ct++; if (ct % 8 == 0) { ds += "\n"; } else { ds += "\t"; } } return ds; } } public class Hand { private List _cards; public Hand() { _cards = new List(Game.NUM_CARDS); } public void Add(Card c) { _cards.Add(c); } public Card Peek(int pos) { return _cards[pos]; } public override string ToString() { return String.Format("{0}-{1}", _cards[0], _cards[1]); } } public class Player { // data needed for decision making private int _numCards; public Player(int numCards) { _numCards = numCards; } public int ChooseCard() { return Game.Random.Next(0, _numCards); } public char ChooseSuit() { return Card.SUITS[Game.Random.Next(0, 4)]; } public bool Turn() { // select which card (0 or 1) // yell a suit (random) // get the card from the hand // compare the suit to the card // win or not return false; } } public class Game { public const int NUM_PLAYERS = 2; public const int NUM_CARDS = 2; public static Random Random = new Random(); private Deck _deck; private Player[] _players; private Hand[] _hands; private int _turn; public Game() { _players = new Player[NUM_PLAYERS]; _hands = new Hand[NUM_CARDS]; } public void Play() { Setup(); while (Turn()) { } Win(); } public void Setup() { // create all the objects _deck = new Deck(1); for (int i=0;i