Пример #1
0
        //Excecutes a unit test of class Hand.
        static void testHand()
        {
            Console.WriteLine("\nTest Hand:");
              Deck deck = new Deck();
              Hand currentHand = new Hand();

              for (int i = 0; i < 2; i++)
              {
              currentHand.add(deck.deal());
              }
              Console.WriteLine(currentHand.ToString());

              //Test the hand score.

              Console.WriteLine("\nTest Hand Score:");
              Console.WriteLine(currentHand.BJscore());

              //Test for the first card Dealt.
              Console.WriteLine("\nTest first card dealt:");
              Console.WriteLine(currentHand.firstCardDealt().ToString());

              //Test for giving cards back to dealer.
              Console.WriteLine("\nTest Giving cards to dealer (end of round action): ");
              foreach (Card c in currentHand.giveCardsBackToDealer())
              {
              Console.WriteLine(c.ToString());
              }
              Console.WriteLine("(The above cards have been sucsessfully returned to the dealer.)");

              //NO TEST FOR THE REMOVE METHOD, AS IT IS NOT USED IN MY PROGRAM
        }
Пример #2
0
        //Executes a unit test of class Deck.
        static void testDeck()
        {
            //Creates a deck and prints out the first 20 cards dealt.
            Console.WriteLine("\nTest Deck (prints first 20 cards):");
            Deck deck = new Deck();
            for (int i = 0; i < 20; i++)
            {
                Card newcard = deck.deal();
                Console.WriteLine(newcard.ToString());
            }
            Console.WriteLine();

            //Test the acceptDiscards method, and print out the discard pile.
            Hand newHand = new Hand();
            for (int i = 0; i < 3; i++)
            {
                newHand.add(deck.deal());
            }
            deck.acceptDiscards(newHand.surrenderCards());
            Console.WriteLine("Test collecting cards from players (prints 0 if the hand is empty and received)");
            if (newHand.ToString().CompareTo("") == 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("ERROR.");
            }
            Console.WriteLine("(The above cards were sucsessfully dealt, and recieved by the dealer, and added to the discard pile.)");
        }
Пример #3
0
        /// <summary>
        /// Runs unit tests for the Android class.
        /// </summary>
        static void TestAndroid()
        {
            Hand h = new Hand();
            Console.WriteLine("Tests for the Android class:\n");
            Android c3po = new Android("c3po", h);
            //Console.WriteLine("Output Window with 'c3po' as banner should have popped up."); //Not applicable in Blackjack3
            Deck d = new Deck();

            //Test getCard() and showHand().
            c3po.getsCard(d.deal());
            c3po.getsCard(d.deal());
            Console.WriteLine("Current Hand after having been dealt two cards: \n");
            h = c3po.showHand();
            Console.WriteLine(h.ToString());

            //Tests outcomeOfRound()
            Console.WriteLine("Test a win by pressing enter.");
            Console.ReadLine();
            c3po.outcomeOfRound(Outcome.Win);
            Console.WriteLine("Sucsess.");

            //Tests wantsCard()
            Console.WriteLine("Test wantsCard() by pressing enter.");
            Console.ReadLine();
            c3po.wantsCard();
            Console.WriteLine("Success.\n");
        }
Пример #4
0
        //Excecutes a unit test of class Deck.
        static void testDeck()
        {
            //Creates a deck and prints out the first 20 cards dealt.
              Console.WriteLine("\nTest Deck:");
              Deck deck = new Deck();
              for (int i = 0; i < 20; i++)
              {
              Card newcard = deck.deal();
              Console.WriteLine(newcard.ToString());
              }
              Console.WriteLine();

              //Test the collectCardsFromPlayers method, and print out the discard pile.
              Hand newHand = new Hand();
              for (int i = 0; i < 3; i++)
              {
              newHand.add(deck.deal());
              }
              deck.collectCardsFromPlayers(newHand.giveCardsBackToDealer());
              Console.WriteLine("Test collecting cards from players/adding cards to discard pile: ");
              foreach (Card c in deck.discardPile)
              {
              Console.WriteLine(c.ToString());
              }
              Console.WriteLine("(The above cards were sucsessfully dealt, and recieved by the dealer, and added to the discard pile.)");
        }
 /// <summary>
 /// A constructor for the form that sets up its inital state. 
 /// </summary>
 /// <param name="h">The house player's hand.</param>
 public HouseHandForm(Hand h)
 {
     InitializeComponent();
     uxHousePlayersHandLabel.Text = "(No cards in hand)";
     uxStaticTopCardLabel.Visible = false;
     this.h = h;
 }
Пример #6
0
 /// <summary>
 /// A constructor that creates the form, as well as a new hand for the Android Player.
 /// </summary>
 /// <param name="name">The name of the Android Player.</param>
 public Android(string name, Hand h)
 {
     this.h = h;
     rounds = 0;
     wins = 0;
     playersName = name;
 }
Пример #7
0
 /// <summary>
 /// The constructor creates a new hand, constructs a new form for the player, and assigns the name of the player to the text of that form.
 /// </summary>
 /// <param name="name">The name of the player.</param>
 public Human(string name, Hand h)
 {
     this.h = h;
     rounds = 0;
     wins = 0;
     playerName = name;
     cardCounter = 0;
 }
 /// <summary>
 /// Constructs the inital view for the Scoreboard form.
 /// </summary>
 /// <param name="h">The Human Player's hand.</param>
 /// <param name="wins">The Human Player's wins.</param>
 /// <param name="rounds">A method that returns the number of rounds played.</param>
 /// <param name="status">A method that returns the game status in string format.</param>
 public Scoreboard(Hand h, ObserverInt wins, ObserverInt rounds, ObserverString status)
 {
     this.h = h;
     this.wins = wins;
     this.rounds = rounds;
     this.status = status;
     InitializeComponent();
 }
Пример #9
0
 static void testHand() {
     Console.WriteLine("test hand------");
     Deck d2 = new Deck();
     Hand h1 = new Hand();
     for (int i = 0; i < 5; i++) {
         h1.add(d2.deal());
     }
     Console.WriteLine(h1);
 }
 /// <summary>
 /// Constructor initalizes the hand text to an empty string, along with assigning the fields below. 
 /// </summary>
 /// <param name="newRoundMethod">Method for starting a new round.</param>
 /// <param name="anotherCardMethod">Method for receiving another card from the dealer.</param>
 /// <param name="holdCardsMethod">Method for keeping the cards already in the hand, and passing the round on to the next player.</param>
 /// <param name="human">The Human player's hand.</param>
 public HumansHandForm(InputHandler newRoundMethod, InputHandler anotherCardMethod, InputHandler holdCardsMethod, Hand human, Hand house)
 {
     InitializeComponent();
     this.newRoundMethod = newRoundMethod;
     this.anotherCardMethod = anotherCardMethod;
     this.holdCardsMethod = holdCardsMethod;
     this.human = human;
     this.house = house;
     uxHandLabel.Text = "(No cards in hand)";
     uxAddAnotherCardButton.Enabled = false;
     uxHoldCardsButton.Enabled = false;
     uxStaticTopCardLabel.Visible = false;
 }
Пример #11
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new OutputForm()); //Instead, we're suing OutputForm as a passive output form...
            //that each player constructs on thier own.

            // WRITE ME: CONSTRUCT MODEL OBJECTS
            //           CONSTRUCT CONTROLLER
            //           CONSTRUCT VIEWS
            //           REGISTER VIEWS WITH CONTROLLER
            //           START THE SYSTEM

            //Models are created, and later passed on to the entities that own them (dealer/players).
            Deck d = new Deck();
            Hand humanHand = new Hand();
            Hand houseHand = new Hand();

            //Players!
            Player housePlayer = new Android("House", houseHand);
            List<Player> guestPlayers = new List<Player>();
            guestPlayers.Add(new Human("You", humanHand));

            //Controller (The Dealer)!
            Dealer dealer = new Dealer(guestPlayers, housePlayer, d);

            //Construct views!
            HumansHandForm humanForm = new HumansHandForm(dealer.newRound, dealer.dealACardToHuman, dealer.playerDecidedToHold, humanHand, houseHand);
            Scoreboard scoreboard = new Scoreboard(humanHand, dealer.numberOfWins, dealer.numberOfRounds, dealer.gameStatus);
            HouseHandForm houseForm = new HouseHandForm(houseHand);

            //Display views!
            humanForm.Show();
            scoreboard.Show();
            houseForm.Show();

            //Register the methods that update the forms.
            dealer.registerOb(humanForm.showhand);
            dealer.registerObHouseHandOnly(houseForm.updateHand);
            dealer.registerOb(scoreboard.updateScore);
            dealer.registerOb(scoreboard.updateWins);
            dealer.registerOb(scoreboard.updateRounds);
            dealer.registerOb(scoreboard.updateStatus);

            //The HumansHandForm will serve as our main view.
            Application.Run(humanForm);

            //We will conculde our program with a cute little message box before exiting.
            MessageBox.Show("Thanks for playing! Click to exit.", "Exit");
        }
Пример #12
0
        /// <summary>
        /// Runs unit tests for the Dealer class.
        /// </summary>
        static void TestDealer()
        {
            Hand h1 = new Hand();
            Hand h2 = new Hand();
            Deck d = new Deck();

            Console.WriteLine("Tests for the Dealer Class");
            List<Player> guests = new List<Player>();
            Human George = new Human("George", h1);
            Android r2d2 = new Android("r2d2", h2);
            guests.Add(George);

            Dealer dealer = new Dealer(guests, r2d2, d);

            Console.WriteLine("Test number of Rounds: " + dealer.numberOfRounds() + "\n(Should display 0)");
            Console.WriteLine("Test number of wins: " + dealer.numberOfWins() + "\n(Should display 0)");
            Console.WriteLine("Test game status: " + dealer.gameStatus() + "\n(Should display status)");

            Console.WriteLine("This concludes all of the unit test that don't require use of the forms.");
            Console.WriteLine("If this point has been reached, then all tests have been completed sucsessfully.");
            Console.WriteLine("Please press enter when you are ready to quit.");
        }
Пример #13
0
        //Executes a unit test of class Hand.
        static void testHand()
        {
            Console.WriteLine("\nTest Hand:");
            Deck deck = new Deck();
            Hand currentHand = new Hand();

            for (int i = 0; i < 2; i++)
            {
                currentHand.add(deck.deal());
            }
            Console.WriteLine(currentHand.ToString());

            //Test the hand score.
            Console.WriteLine("\nTest Hand Score:");
            Console.WriteLine(currentHand.BJscore());

            //Test for giving cards back to dealer.
            Console.WriteLine("\nTest Giving cards to dealer (end of round action): ");
            foreach (Card c in currentHand.surrenderCards())
            {
                Console.WriteLine(c.ToString());
            }
            Console.WriteLine("(The above cards have been sucsessfully returned to the dealer.)");
        }
Пример #14
0
        /// <summary>
        /// Runs unit tests for the Human class.
        /// </summary>
        static void TestHuman()
        {
            Hand h = new Hand();
            Console.WriteLine("Tests for the Human class:\n");
            Human Christian = new Human("Christian", h);
            //Console.WriteLine("Output Window with 'Christian' as banner should have popped up."); //Not Applicable in Blackjack3
            Deck d = new Deck();

            //Test getCard() and showHand().
            Christian.getsCard(d.deal());
            Christian.getsCard(d.deal());
            Console.WriteLine("Current Hand after having been dealt two cards: \n");
            h = Christian.showHand();
            Console.WriteLine(h.ToString());

            //Tests outcomeOfRound()
            Console.WriteLine("Test a win by pressing enter.");
            Console.ReadLine();
            Christian.outcomeOfRound(Outcome.Win);
            Console.WriteLine("Sucsess.");

            //Tests wantsCard() NOT USED IN Blackjack3
            Console.WriteLine("Test wantsCard() by pressing enter.");
            Console.ReadLine();
            Christian.wantsCard();
            Console.WriteLine("Success.\n");
        }