Ejemplo n.º 1
0
 /// <summary>
 /// Allows the computer to have a turn
 /// Pre: User had stood or has reached 21
 /// Post: Allows the Comptuer to have a turn
 /// </summary>
 private void ComputersTurn()
 {
     TwentyOne.DealACard(DEALER);
     DisplayHandValue(DEALER);
     TwentyOne.DetermineWinner();
     DisplayGamesWon();
     if (TwentyOne.HandValue(DEALER) > TwentyOne.MAXVALUE)
     {
         DealerHasBusted.Visible = true;
     }
 }
Ejemplo n.º 2
0
        // GET: Game
        public ActionResult GetValue()
        {
            TwentyOne game = new TwentyOne()
            {
                Player       = "User",
                CurrentValue = 0
            };

            Session["game"] = game;
            return(View(game));
        }
Ejemplo n.º 3
0
        // GET: TwentyOne
        public ActionResult TwentyOne()
        {
            var twentyOneModel = new TwentyOne
            {
                PresentValue     = 0,
                ActiveGameStatus = new GameStatus()
            };

            Session["activeGame"] = twentyOneModel;
            return(View(twentyOneModel));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Displays the Users hand Value and updates the players hand image
 /// </summary>
 private void DisplayHandValue(int player)
 {
     if (player == PLAYER)
     {
         lblPlayersHandValue.Text = TwentyOne.HandValue(PLAYER).ToString();
         DisplayGuiHand(TwentyOne.GetHand(PLAYER), playerTableLayoutPanel);
     }
     else
     {
         lblDealersHandvalue.Text = TwentyOne.HandValue(DEALER).ToString();
         DisplayGuiHand(TwentyOne.GetHand(DEALER), dealerTableLayoutPanel);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds a card to a Users Hand and then checks if they have gone bust or not
 /// Pre: They must not have 21 already and have hit the hit button
 /// Post: Deals a card to the player
 /// </summary>
 private void btnHit_Click(object sender, EventArgs e)
 {
     TwentyOne.AddCard(PLAYER);
     DisplayGuiHand(TwentyOne.GetHand(PLAYER), playerTableLayoutPanel);
     CheckHandForAce();
     lblPlayersHandValue.Text = TwentyOne.HandValue(PLAYER).ToString();
     if (TwentyOne.HandValue(PLAYER) > TwentyOne.MAXVALUE)
     {
         TwentyOne.DetermineWinner();
         PlayerHasBusted.Visible = true;
         DisplayGamesWon();
         DisableButtons();
     }
 }
Ejemplo n.º 6
0
        // GET: TwentyOne
        public ActionResult TwentyOne()
        {
            var twentyOneModel = new TwentyOne
            {
                GameFields = new List <GameField>
                {
                    new GameField(1, 1, "", "hotpink"),
                    new GameField(2, 2, "", "hotpink"),
                    new GameField(0, 0, "disabled", ""),
                    new GameField(0, 3, "disabled", "")
                },
                ActiveGameStatus = new GameStatus()
            };

            Session["activeGame"] = twentyOneModel;
            return(View(twentyOneModel));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets up the game of 21
 /// </summary>
 private void btnDealCards_Click(object sender, EventArgs e)
 {
     TwentyOne.SetUpGame();
     DisplayGuiHand(TwentyOne.GetHand(DEALER), dealerTableLayoutPanel);
     DisplayGuiHand(TwentyOne.GetHand(PLAYER), playerTableLayoutPanel);
     TwentyOne.DisplayHand(DEALER);
     TwentyOne.DisplayHand(PLAYER);
     DisplayHandValue(PLAYER);
     DisplayHandValue(DEALER);
     lblValue.Text           = TwentyOne.GetNumOfUserAcesWithValueOne().ToString();
     DealerHasBusted.Visible = false;
     PlayerHasBusted.Visible = false;
     btnDealCards.Enabled    = false;
     btnHit.Enabled          = true;
     btnStand.Enabled        = true;
     CheckHandForAce();
     CheckHandForAce();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Checks the hand if it has an Ace or not, and allows the user to specify its value
 /// Pre: A Ace in the players hand
 /// Post: Changes the value of the Ace
 /// </summary>
 public void CheckHandForAce()
 {
     if (TwentyOne.CheckAces(PLAYER))
     {
         DialogResult dialogResult = MessageBox.Show("Would You like the ace to be 1?",
                                                     "You have been dealt and Ace", // The MessageBox's caption.
                                                     MessageBoxButtons.YesNo,
                                                     MessageBoxIcon.Question);
         if (dialogResult == DialogResult.Yes)
         {
             TwentyOne.IncreaseNumOfUserAcesWithValueOne();
             lblValue.Text = TwentyOne.GetNumOfUserAcesWithValueOne().ToString();
         }
     }
     DisplayHandValue(PLAYER);
     if (TwentyOne.HandValue(PLAYER) == TwentyOne.MAXVALUE)
     {
         DisableButtons();
         ComputersTurn();
     }
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.AutoFlush = true;

            do
            {
                DisplayMenu(mainMenu);
                menuOption = GetMenuOption(EXIT, HIGHEST_MENU_NUMBER);
                switch (menuOption)
                {
                case SIMPLE_TWO_UP:
                    TwoUp.PlayConsole();
                    break;

                case TWENTY_ONE:
                    TwentyOne.PlayConsole();
                    break;

                case CRAZY_EIGHTS:
                    CrazyEights.PlayConsole();
                    break;

                case PIG:
                    Pig.PlayConsole();
                    break;

                case EXIT:
                    DisplayEndMessage();
                    break;

                default:
                    Trace.WriteLine("Major Logical error - this message should not appear!");
                    break;
                } // end switch
            } while (menuOption != EXIT);
        }         //end Main
Ejemplo n.º 10
0
 //Displays the games won
 private void DisplayGamesWon()
 {
     lblPlayerGamesWonValue.Text = TwentyOne.GetNumOfGamesWon(PLAYER).ToString();
     lblDealerGamesWonValue.Text = TwentyOne.GetNumOfGamesWon(DEALER).ToString();
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            DateTime datetime = new DateTime(1995, 5, 23, 8, 32, 45);

            Console.WriteLine("Welcome to the Grand Hotel and Casino." +
                              "Let's start by telling me your name: ");
            string playerName = Console.ReadLine();

            if (playerName.ToLower() == "admin")
            {
                List <ExceptionEntity> Exceptions = ReadExceptions();
                foreach (var exception in Exceptions)
                {
                    Console.WriteLine(exception.Id + "| ");
                    Console.WriteLine(exception.ExceptionType + "| ");
                    Console.WriteLine(exception.ExceptionMessage + "| ");
                    Console.WriteLine(exception.TimeStamp + "| ");
                    Console.WriteLine();
                }
                Console.ReadLine();
                return;
            }
            bool Validanswer = false;
            int  bank        = 0;

            while (!Validanswer)
            {
                Console.WriteLine("And how much money did you bring today?");
                Validanswer = int.TryParse(Console.ReadLine(), out bank);
                if (!Validanswer)
                {
                    Console.WriteLine("please enter digits only,no decimals");
                }
            }
            //Console.WriteLine("And how much money did you bring today?");
            //bank = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Hello, {0}. Would you like to join a game of 21 right now? " + playerName);
            string answer = Console.ReadLine().ToLower();

            if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "ya")
            {
                Player player = new Player(playerName, bank);
                player.Id = Guid.NewGuid();
                using (StreamWriter file = new StreamWriter(@"C:\Users\VrinMan Dulay\Documents\test.txt", true))
                {
                    file.WriteLine(DateTime.Now);
                    file.WriteLine(player.Id);
                }
                Game game = new TwentyOne();
                game += player;
                player.isActivePlaying = true;
                while (player.isActivePlaying && player.Balance > 0)
                {
                    try
                    {
                        game.Play();
                    }
                    catch (FraudException ex)
                    {
                        Console.WriteLine(ex.Message);
                        updateDBWtihException(ex);
                        Console.ReadLine();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error Occured. Please Contact to your system administrator");
                        updateDBWtihException(ex);
                        Console.ReadLine();
                        return;
                    }
                }
                game -= player;
                Console.WriteLine("Thank you for playing!");
            }
            Console.WriteLine("Feel free to look around the casino. Bye for now.");
            Console.ReadLine();
            //Deck deck = new Deck();
            //deck.Shuffle(3);
            //foreach(Card card in deck.Cards)
            //{
            //    Console.WriteLine(card.Face + " of " + card.Suit);
            //}
            //Console.WriteLine(deck.Cards.Count);
            //Console.ReadLine();
        }