static void Main(string[] args) { const string casinoName = "Grand Hotel and Casino"; Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName); string playerName = Console.ReadLine(); 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("Hello, " + playerName + ",would you like to join a game of 21 right now?,"); 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\Student\Downloads\myProjects.txt", true)) { file.WriteLine(player.Id); } Game game = new TwentyOneGame(); game += player; player.isActivelyPlaying = true; while (player.isActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException) { Console.WriteLine("Security! Kick this person out."); Console.ReadLine(); return; } catch (Exception) { Console.WriteLine("An error occurred. Please contact your System Administrator."); 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(); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Grand Hotel and Casino. Let's start by telling me your name"); string playerName = Console.ReadLine(); Console.WriteLine("And how much money did you bring today?"); int 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); Game game = new TwentyOneGame(); game += player; player.isActivelyPlaying = true; while (player.isActivelyPlaying && player.Balance > 0) { game.Play(); } game -= player; Console.WriteLine("Thank you for playing!"); } Console.WriteLine("Feel freee to look around the casino. Bye for now."); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("Welcome to the Grand West Casino. Lets start by telling me your name."); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.WriteLine(exception.TimeStamp + " | \n"); } Console.Read(); return; } Console.WriteLine("What is your buy in today?"); int 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 == "y" || answer == "yeah" || answer == "ya") { Player player = new Player(playerName, bank); Game game = new TwentyOneGame(); game += player; player.isActivelyPlaying = true; // Game Loop while (player.isActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occured please contact your system administrator."); UpdateDbWithException(ex); Console.ReadLine(); return; } } game -= player; Console.WriteLine("Thank you for playing!"); } Console.WriteLine("Feel free to look around the casino."); Console.Read(); }
/// <summary> /// Update all the dunamic values on the form. /// </summary> /// <param name="who"></param> private void UpdateDynamicValues(int who) { if (who == PLAYER) { int playerPointsTotal = TwentyOneGame.CalculateHandTotal(PLAYER); int acesWithValueOne = TwentyOneGame.GetNumOfUserAcesWithValueOne(); playerPointsLabel.Text = (playerPointsTotal).ToString(); acesWithValueOneTextbox.Text = (acesWithValueOne).ToString(); DisplayGuiHand(TwentyOneGame.GetHand(PLAYER), playerTableLayoutPanel); } else if (who == DEALER) { int dealerPointsTotal = TwentyOneGame.CalculateHandTotal(DEALER); dealerPointsLabel.Text = (dealerPointsTotal).ToString(); DisplayGuiHand(TwentyOneGame.GetHand(DEALER), dealerTableLayoutPanel); } else if (who == PLAYER_AND_DEALER) { int playerPointsTotal = TwentyOneGame.CalculateHandTotal(PLAYER); int acesWithValueOne = TwentyOneGame.GetNumOfUserAcesWithValueOne(); int dealerPointsTotal = TwentyOneGame.CalculateHandTotal(DEALER); playerPointsLabel.Text = (playerPointsTotal).ToString(); acesWithValueOneTextbox.Text = (acesWithValueOne).ToString(); dealerPointsLabel.Text = (dealerPointsTotal).ToString(); DisplayGuiHand(TwentyOneGame.GetHand(PLAYER), playerTableLayoutPanel); DisplayGuiHand(TwentyOneGame.GetHand(DEALER), dealerTableLayoutPanel); } }
/// <summary> /// Setup the game on click of the deal button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dealButton_Click(object sender, EventArgs e) { TwentyOneGame.SetUpGame(); UpdateDynamicValues(PLAYER_AND_DEALER); enableButtons(); dealButton.Enabled = false; }
static void Main(string[] args) { Game game = new TwentyOneGame(); Console.WriteLine("Welcome to the Blackjack table. How many players today?"); int numberOfPlayers = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < numberOfPlayers; i++) { Console.WriteLine("Please enter your name:"); string playerName = Console.ReadLine(); bool validAnswer = false; int bank = 0; while (!validAnswer) { Console.WriteLine("How much money would you like to put up?"); validAnswer = int.TryParse(Console.ReadLine(), out bank); if (!validAnswer) { Console.WriteLine("Please enter digits only, no decimals."); } } Player newPlayer = new Player(playerName, bank); newPlayer.Id = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"C:\Users\andye\logs\cardlog.txt", true)) { file.WriteLine(newPlayer.Id); } game += newPlayer; newPlayer.IsActive = true; } while (game.Players.Count > 0 && game.Players.Sum(x => x.Balance) > 0) { try { game.Play(); } catch (FraudException) { Console.WriteLine("Invalid bet entry. Security has been alerted to your activity. Please vacate the premises immediately."); Console.Read(); return; } catch (Exception) { Console.WriteLine("An error occurred. Please contact your system administrator."); Console.Read(); return; } } Console.WriteLine("Thank you for playing. Come again soon!"); Console.Read(); }
/// <summary> /// Play the dealers turn /// </summary> private void playDealersTurn() { TwentyOneGame.PlayForDealer(); checkPlayerBusted(DEALER); UpdateDynamicValues(DEALER); checkExceedMaximumCards(DEALER); promptNextGame(); }
static void Main(string[] args) { Console.WriteLine("Welcome lets play. What is your name?:"); string playerName = Console.ReadLine(); bool validAnswer = false; int bank = 0; while (!validAnswer) { Console.WriteLine("How much did you bring to spend:"); validAnswer = int.TryParse(Console.ReadLine(), out bank); if (!validAnswer || bank < 0) { Console.WriteLine("Please Enter Valid Digits only, no loose change or negative amounts."); validAnswer = false; } } Console.WriteLine("Hello, {0}! Would you like to join a game fo 21?", playerName); string answer = Console.ReadLine().ToLower(); if (answer == "yes" || answer == "yeah" || answer == "y" || answer == "yaeh" || answer == "yse") { Player player = new Player(playerName, bank); Game game = new TwentyOneGame(); player.Id = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"C:\Users\rohit\source\repos\The-Tech-Academy-Basic-C-Sharp-Projects\CardGame\CardGame\Log\log.txt", true)) { file.WriteLine(player.Id); } game += player; player.IsActive = true; while (player.IsActive && player.Balance > 0) { try { game.Play(); } catch (Exception) { Console.WriteLine("An error occured please contact your system Adminstrator"); } } game -= player; Console.WriteLine("Thank you for playing!"); } Console.WriteLine("Feel free to look around. Bye for now!"); Console.ReadLine(); //foreach (Card card in deck.Cards) //{ // Console.WriteLine(card.Face + " of " + card.Suit); //} }
private void btnStand_Click(object sender, EventArgs e) { TwentyOneGame.PlayForDealer(); this.gameCurrent = false; this.UpdateDisplay(false); this.btnHit.Enabled = false; this.btnStand.Enabled = false; this.btnDeal.Enabled = true; }
/// <summary> /// Utility method to deal a card, also handles aces and first run of cards /// </summary> /// <param name="who">Which player</param> /// <param name="firstRun">Prevent message box and assign default value of 1 for aces</param> /// <returns></returns> private Card DealCardTo(int who, bool firstRun) { Card card = TwentyOneGame.DealOneCardTo(who); // Is it an ace if (!firstRun && who == TwentyOneGame.PLAYER_USER && card.GetFaceValue() == FaceValue.Ace) { if (MessageBox.Show("Count ace as 1?", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes) { TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); } } this.UpdateDisplay(false); return(card); }
/// <summary> /// Play the game on click of the hit button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void hitButton_Click(object sender, EventArgs e) { Card playerDeltCard = TwentyOneGame.DealOneCardTo(PLAYER); FaceValue faceValueOfDeltCard = playerDeltCard.GetFaceValue(); if (faceValueOfDeltCard == FaceValue.Ace) { DialogResult messageBoxResult = ClassAssignment.Program.showYesNoMessageBox("Count Ace as 1?", "You got an Ace!"); if (messageBoxResult == DialogResult.Yes) { TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); } } checkPlayerBusted(PLAYER); UpdateDynamicValues(PLAYER); checkExceedMaximumCards(PLAYER); }
/// <summary> /// Check to see if the player is going to exceed 9 cards in their hand and prevent them from doing so. /// </summary> /// <param name="who"></param> private void checkExceedMaximumCards(int who) { if (who == PLAYER) { int amountOfPlayerCardsInHand = TwentyOneGame.GetHand(PLAYER).GetCount(); if (amountOfPlayerCardsInHand >= MAX_NUMBER_OF_CARDS_ALLOWED) { hitButton.Enabled = false; } } else if (who == DEALER) { int amountOfDealerCardsInHand = TwentyOneGame.GetHand(DEALER).GetCount(); if (amountOfDealerCardsInHand >= MAX_NUMBER_OF_CARDS_ALLOWED) { promptNextGame(); } } }
/// <summary> /// Present the user with the results when they decide to cancel the game and close the window. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cancelButton_Click(object sender, EventArgs e) { int dealerGamesWon = TwentyOneGame.GetNumOfGamesWon(DEALER); int playerGamesWon = TwentyOneGame.GetNumOfGamesWon(PLAYER); if (dealerGamesWon > playerGamesWon) { Program.showOKMessageBox("House won. Better luck next time."); } else if (playerGamesWon > dealerGamesWon) { Program.showOKMessageBox("You won! Well done."); } else { Program.showOKMessageBox("It was a draw!"); } TwentyOneGame.ResetTotals(); this.Close(); }
} // End DisplayGuiHand /// <summary> /// Copies data from logic class to display /// </summary> /// <param name="firstRun">Prevent exceptions resulting from no game being played prior</param> private void UpdateDisplay(bool firstRun) { // Show number of games won this.gamesWonLabels[TwentyOneGame.PLAYER_USER].Text = TwentyOneGame.GetNumOfGamesWon(TwentyOneGame.PLAYER_USER).ToString(); this.gamesWonLabels[TwentyOneGame.PLAYER_CPU].Text = TwentyOneGame.GetNumOfGamesWon(TwentyOneGame.PLAYER_CPU).ToString(); // Show how many aces the user has that have a value of 1 this.lblOneAces.Text = TwentyOneGame.GetNumOfUserAcesWithValueOne().ToString(); if (!firstRun) { // Show the hands this.DisplayGuiHand(TwentyOneGame.GetHand(TwentyOneGame.PLAYER_USER), this.tableLayoutPanels[TwentyOneGame.PLAYER_USER]); this.DisplayGuiHand(TwentyOneGame.GetHand(TwentyOneGame.PLAYER_CPU), this.tableLayoutPanels[TwentyOneGame.PLAYER_CPU]); int pointsPlayer = TwentyOneGame.CalculateHandTotal(TwentyOneGame.PLAYER_USER); int pointsCpu = TwentyOneGame.CalculateHandTotal(TwentyOneGame.PLAYER_CPU); // Show whether a player is busted this.bustedLabels[TwentyOneGame.PLAYER_USER].Visible = !this.gameCurrent && pointsPlayer > TwentyOneGame.MAX_POINTS; this.bustedLabels[TwentyOneGame.PLAYER_CPU].Visible = !this.gameCurrent && pointsCpu > TwentyOneGame.MAX_POINTS; // Only show if they have more than 0 points this.pointsLabels[TwentyOneGame.PLAYER_USER].Visible = pointsPlayer > 0; this.pointsLabels[TwentyOneGame.PLAYER_CPU].Visible = pointsCpu > 0; // Show points this.pointsLabels[TwentyOneGame.PLAYER_USER].Text = pointsPlayer.ToString(); this.pointsLabels[TwentyOneGame.PLAYER_CPU].Text = pointsCpu.ToString(); if (!this.gameCurrent && pointsPlayer >= TwentyOneGame.MAX_POINTS) { btnDeal.Enabled = true; btnHit.Enabled = false; btnStand.Enabled = false; } } // Force visual update this.Update(); }
public ActionResult Play(Player player) { if (!ModelState.IsValid) { return(View("Index", player)); } TwentyOneGame game = new TwentyOneGame(); game.Players.Add(player); player.isActivelyPlaying = true; player.Hand = new List <Card>(); player.Stay = false; game.Dealer = new TwentyOneDealer() { Hand = new List <Card>(), Stay = false, Deck = new Deck(), }; game.Dealer.Deck.Shuffle(); return(View(game)); }
static void Main(string[] args) { TwentyOneGame game = new TwentyOneGame(); game.Players = new Lists <string>() { "Jesse", "Bill", "Bob", }; game.ListPlayers(); 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(); }
/// <summary> /// Check if the player has been busted. /// </summary> /// <param name="who"></param> private void checkPlayerBusted(int who) { if (who == PLAYER) { int playerPointsTotal = TwentyOneGame.CalculateHandTotal(PLAYER); if (playerPointsTotal > 21) { disableButtons(); playerBustedLabel.Visible = true; playDealersTurn(); } } else if (who == DEALER) { int dealerPointsTotal = TwentyOneGame.CalculateHandTotal(DEALER); if (dealerPointsTotal > 21) { dealerBustedLabel.Visible = true; } } }
private void btnCancel_Click(object sender, EventArgs e) { int playerPoints = TwentyOneGame.CalculateHandTotal(TwentyOneGame.PLAYER_USER); int cpuPoints = TwentyOneGame.CalculateHandTotal(TwentyOneGame.PLAYER_CPU); // Show friendly exit message string message = "It was a draw!"; if (playerPoints > cpuPoints) { message = "You won! Well done."; } else if (cpuPoints > playerPoints) { message = "House won! Better luck next time."; } MessageBox.Show(message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
} //end of DealButton_Click private void HitButton_Click(object sender, EventArgs e) { //Ask player if they want to use Ace as 1. if (TwentyOneGame.DealOneCardTo(1).GetFaceValue() == FaceValue.Ace) { DialogResult choice = MessageBox.Show("Count Ace as 1?", "You got an Ace!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //If choice is Yes, Ace card is given a 1 value. if (choice == DialogResult.Yes) { TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); AmountOfAcesAsOne.Text = TwentyOneGame.GetNumOfUserAcesWithValueOne().ToString(); } //end of if statement } //end of if statement //Calculates totals. TwentyOneGame.CalculateHandTotal(1); //Updates the points text. PointsLabel2.Text = TwentyOneGame.GetTotalPoints(1).ToString(); //Updates GUI panels. DisplayGuiHand(TwentyOneGame.GetHand(1), LayoutPanel2); //If players points go over 21.. if (TwentyOneGame.GetTotalPoints(1) > 21) { //Show BUSTED label. BustedLabel2.Visible = true; //Updates games won. Number1.Text = TwentyOneGame.GetNumOfGamesWon(0).ToString(); //Enables DealButton again for another Game, and disables Hit and stand buttons. DealButton.Enabled = true; HitButton.Enabled = false; StandButton.Enabled = false; } //end of if statement } //end of HitButton_Click
} //end of StandButton_Click private void CancelButton_Click(object sender, EventArgs e) { //Reset totals. TwentyOneGame.ResetTotals(); //If player and dealer has the same amount of games won. if (TwentyOneGame.GetNumOfGamesWon(0) == TwentyOneGame.GetNumOfGamesWon(1)) { MessageBox.Show("It was a draw!"); } //If dealer has less games won than players show player won message. else if (TwentyOneGame.GetNumOfGamesWon(0) > TwentyOneGame.GetNumOfGamesWon(1)) { MessageBox.Show("House won! Better luck next time!"); } //Otherwise show house won message. else { MessageBox.Show("You won! Well done."); }//end if //Close window. this.Close(); }//end of CancelButton_Click
} //end of HitButton_Click private void StandButton_Click(object sender, EventArgs e) { //While Dealer's points are under 17.. while (TwentyOneGame.GetTotalPoints(0) < 17) { //Dealer plays. TwentyOneGame.PlayForDealer(); //Updates points. PointsLabel1.Text = TwentyOneGame.GetTotalPoints(0).ToString(); //Updates GUI. DisplayGuiHand(TwentyOneGame.GetHand(0), LayoutPanel1); } //Disables Stand and Hit button and enables DealButton. StandButton.Enabled = false; HitButton.Enabled = false; DealButton.Enabled = true; //If Dealer's points are over 21.. if (TwentyOneGame.GetTotalPoints(0) > 21) { //Show BUSTED Label BustedLabel1.Visible = true; //Updates Games won of player. Number2.Text = TwentyOneGame.GetNumOfGamesWon(1).ToString(); } else { //Otherwise dealer plays TwentyOneGame.PlayForDealer(); //Updates Games won. Number1.Text = TwentyOneGame.GetNumOfGamesWon(0).ToString(); Number2.Text = TwentyOneGame.GetNumOfGamesWon(1).ToString(); } //end of if statement } //end of StandButton_Click
private void btnDeal_Click(object sender, EventArgs e) { this.btnDeal.Enabled = false; this.btnHit.Enabled = true; this.btnStand.Enabled = true; this.gameCurrent = true; TwentyOneGame.SetUpGame(); // Deal initial cards this.DealCardTo(TwentyOneGame.PLAYER_CPU, true); this.DealCardTo(TwentyOneGame.PLAYER_CPU, true); Card card1 = this.DealCardTo(TwentyOneGame.PLAYER_USER, true); Card card2 = this.DealCardTo(TwentyOneGame.PLAYER_USER, true); // If two aces are dealt, both have a value of one if (card1.GetFaceValue() == FaceValue.Ace || card2.GetFaceValue() == FaceValue.Ace) { // Handle two aces being dealt if (card1.GetFaceValue() == FaceValue.Ace && card2.GetFaceValue() == FaceValue.Ace) { TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); } else // Or just one { if (MessageBox.Show("Count ace as 1?", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes) { TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); } } } this.UpdateDisplay(false); }
/// <summary> /// TExst /// </summary> /// <param name="args">testing</param> static void Main(string[] args) { //string text = "Here is some text"; // file will be created or overwritten. @ means read string exactly as written. no escape chars needed //File.WriteAllText(@"C:\users\andy\logs\log.txt",text); //string text = File.ReadAllText(@"C:\users\andy\logs\log.txt"); //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45); //DateTime yearOfGraduation = new DateTime(2013, 6, 1, 16, 34, 22); //TimeSpan ageAtGraduation = yearOfGraduation - yearOfBirth; // when not using the "using System" //System.Console.WriteLine("Welcome to the Grand Hotel and Casino. Let's start by telling me your name."); // Constructor Chain //Player newPlayer = new Player("Andy"); // gets def bal of 100.. making use of constructor chain // Using var. Rule of thumb: if ever the data type is in question, don't use var. not so good for // readability. //var newPlayer = new Player("Andy"); // implicitly define variable. Useful to avoid a lot of typing //Dictionary<string, string> myDictionary = new Dictionary<string, string>(); //or //var myDictionary1 = new Dictionary<string, string>(); // saves typing // declaring constants - they can not change const string casinoName = "Grand Hotel and Casino"; Console.Write("Welcome to the {0}. Let's start by telling me your name.\n>> ", casinoName); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { // Create list of exceptions from the database List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); return; } bool validAnswer = false; int bank = 0; while (!validAnswer) { Console.Write("\nAnd how much money did you bring today?\n>> "); validAnswer = int.TryParse(Console.ReadLine(), out bank); if (!validAnswer) { Console.WriteLine("Please enter only digits with no decimal"); } } Console.Write("\nHello, {0}. Would you like to join a game of 21 right now?\n>> ", playerName); string answer = Console.ReadLine().ToLower(); if (answer == "yes" || answer == "yeah" || answer == "ya" || answer == "y") { Player player = new Player(playerName, bank); // use constructor to create player player.Id = Guid.NewGuid(); // Create a GUID and assign to player using (StreamWriter file = new StreamWriter(@"C:\users\andy\logs\TwentyOneLog.txt", true)) // true indicates append { file.WriteLine(player.Id); } // once this reached, memory resources are disposed of Game game = new TwentyOneGame(); // polymorphism happening here game += player; // using overloaded operators in Game to add player to the list, players player.IsActivelyPlaying = true; while (player.IsActivelyPlaying && player.Balance > 0) { try { // Play one hand game.Play(); // most everything will happen in the Play method to keep the main method clean } catch (FraudException ex) // more specific exceptions first { Console.WriteLine(ex.Message); // written here instead of below. Allows for easy change of message //Console.WriteLine("\nSecurity! Kick this person out for cheating."); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) // Generic exceptions are last { Console.WriteLine("\nAn error occurred. Please contact your System Administrator."); UpdateDbWithException(ex); Console.ReadLine(); return; } } game -= player; Console.WriteLine("\nYour balance is {0}. Thank you for playing!", player.Balance); } Console.WriteLine("\nFeel free to look around the casino. Bye for now."); Console.Read(); }
static void Main(string[] args) { //string text = "Here is some text"; //File.WriteAllText(@"C:\Users\Student\testfile.txt", text); //uses a file path //string text = File.ReadAllText(@"C:\Users\Student\testfile.txt"); //reads text file //DateTime dateTime = new DateTime(1995, 5, 23, 8, 32, 45); //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45); //DateTime yearofGraduation = new DateTime(2013, 6, 1, 16, 34, 22); //TimeSpan ageAtGraduation = yearofGraduation - yearOfBirth; //result in days //Player newPlayer = new Player("Jesse"); //utiiling constructor chain //var newPlary = new Player("Jesse"); //using var const string casinoName = "Gran hotel and Casino"; //creating and using constant (see below on first line of code "welcome..") Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.Exceptionmessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); 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?"); //removed to create above exception handling //int 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); //constructor (see Player.cs) and initialized it with above inputs player.Id = Guid.NewGuid(); //identifer for all new users. globally unique using (StreamWriter file = new StreamWriter(@"C:\Users\Student\testfile.txt", true)) { file.WriteLine(player.Id); //logging } Game game = new TwentyOneGame(); //polymorph to expose overload opperators we made game += player; player.isActivielyPlaying = true; while (player.isActivielyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudExceptions ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occurred. Please contact your System Administrator"); UpdateDbWithException(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.Read(); }
/// <summary> /// Display the number of games won at the end of a game and reset a new round. /// </summary> private void promptNextGame() { playerGamesWonTextbox.Text = (TwentyOneGame.GetNumOfGamesWon(PLAYER)).ToString(); dealerGamesWonTextBox.Text = (TwentyOneGame.GetNumOfGamesWon(DEALER)).ToString(); dealButton.Enabled = true; }
static void Main(string[] args) { Console.WriteLine("Welcome to the Grand Hotel and Casino."); Console.WriteLine("Please enter your name:"); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); return; } bool validAnswer = false; int bank = 0; while (!validAnswer || bank <= 0) { Console.WriteLine("How much money are you playing with today?"); validAnswer = int.TryParse(Console.ReadLine(), out bank); if (!validAnswer || bank <= 0) { Console.WriteLine("Please enter whole positive numbers only (no decimals)."); } } //Console.WriteLine("How much money are you playing with today?"); //int bank = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Hello {0} Would you like to join a game of 21?", playerName); string answer = Console.ReadLine().ToLower(); if (answer == "yes" || answer == "yeah" || answer == "ya" || answer == "y") { Player player = new Player(playerName, bank); player.Id = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"c:\Users\xterr\Desktop\log.txt", true)) { file.WriteLine(player.Id); } Game game = new TwentyOneGame(); game += player; player.isActivelyPlaying = true; while (player.isActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDBWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occurred, please contact your system administrator."); UpdateDBWithException(ex); Console.ReadLine(); return; } } game -= player; Console.WriteLine("Thanks for Playing!!"); } Console.WriteLine("Feel free to look around the casino. Good Bye."); Console.ReadLine(); }
static void Main(string[] args) { // VAR, CONST, CONSTRUCTION CHAIN PRACTICE //var playerNum1 = new Player(); //const string theGreatestPlayerEver = "Number 1"; //var newPlayer = new Player("Alex"); //var newDictionary = new Dictionary<string, string>(); const string casinoName = "Grand Hotel and Casino"; Console.WriteLine("Welcome to the {0}. Let's start by telling me your name.", casinoName); string playerName = Console.ReadLine(); // Used to create instance of player class. if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); return; } // Handles Format Exception bool validAnswer = false; int bank = 0; while (!validAnswer || bank <= 0) { Console.WriteLine("And how much money did you bring today?"); validAnswer = Int32.TryParse(Console.ReadLine(), out bank); // output only happens if TryParse succeeds. if (!validAnswer || bank <= 0) { Console.WriteLine("Please enter digits greater than 0 only, no decimals."); } } 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 == "sure" || answer == "y" || answer == "ya") { Player player = new Player(playerName, bank); // Create a new Player Object using the name and money the user inputted. player.Id = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"C:\Users\alext\OneDrive\Documents\GitHub\The-Tech-Academy-Basic-C-Sharp-Projects\Logs\log.txt", true)) { file.WriteLine(player.Id); } Game game = new TwentyOneGame(); // polymorphism so that we can use those overloaded operation properties. game += player; player.IsActivelyPlaying = true; while (player.IsActivelyPlaying && player.Balance > 0) { try { game.Play(); // Set this to play one hand. After that, check to see if the player wants to continue playing. If so, continue While loop. } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occurred. Please contact your System Administrator."); UpdateDbWithException(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.Read(); /* LAMBDA EXPRESSION PRACTICE */ //int count = deck.Cards.Count(x => x.Face == Face.Ace); // .Count Lambda function. //Console.WriteLine(count); //List<Card> newList = deck.Cards.Where(x => x.Face == Face.King).ToList(); //List<int> numberList = new List<int> { 1, 2, 3, 4365, 234, 34 }; //int sum = numberList.Sum(); //int y = numberList.Sum(x => x += 5); //int max = numberList.Max(); //int min = numberList.Min(); //int chain = numberList.Where(x => x > 20).Sum(); //foreach (Card card in newList) //{ // Console.WriteLine(card.Face + " of " + card.Suit); //} //Game game = new TwentyOneGame(); //game.Players = new List<Player>(); // Player player = new Player() { Name = "Alex" }; //game += player; // game -= player; //// Overload method //public static Deck Shuffle(Deck deck, int times) //{ // for (int i = 0; i < times; i++) // { // deck = Shuffle(deck); // } // return deck; //} //// DateTime Practice //DateTime yearOfBirth = new DateTime(1995, 5, 23, 8, 32, 45); // Multiple overloads //DateTime yearOfGraduation = new DateTime(2013, 6, 1, 16, 34, 22); //TimeSpan ageAtGraduation = yearOfGraduation - yearOfBirth; //Console.WriteLine(yearOfGraduation <= yearOfBirth); }
static void Main() { 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.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); 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 a whole number only."); } } 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); Game game = new TwentyOneGame(); game += player; using (StreamWriter logFile = new StreamWriter(@"C:\Users\Jmark\Documents\Coding Projects\Sample Logs\log.txt", true)) { logFile.Write(DateTime.Now + " "); logFile.WriteLine(player.Id); } player.IsActivelyPlaying = true; while (player.IsActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occured. Please contact your System Administrator."); UpdateDbWithException(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.Read(); }
static void Main(string[] args) { const string casinoName = "Grand Hotel and Casino"; Console.WriteLine("Welcome to the {0}. Let's start by tellling me your name.", casinoName); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List <ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); 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("Hello, {0}. Would you like to join a game of 21?", 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\\Carly Lokare\\Documents\\Log\\log.txt", true)) { file.WriteLine(player.Id); } Game game = new TwentyOneGame(); game += player; player.isActivelyPlaying = true; while (player.isActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occurred. Please contact your System Administrator."); UpdateDbWithException(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.Read(); }
static void Main(string[] args) { const string casinoName = "Console Casino"; Console.WriteLine("Welcome to the {0}. Please enter your name.", casinoName); string playerName = Console.ReadLine(); if (playerName.ToLower() == "admin") { List<ExceptionEntity> Exceptions = ReadExceptions(); foreach (var exception in Exceptions) { Console.Write(exception.Id + " | "); Console.Write(exception.ExceptionType + " | "); Console.Write(exception.ExceptionMessage + " | "); Console.Write(exception.TimeStamp + " | "); Console.WriteLine(); } Console.Read(); return; } bool validAnswer = false; int bank = 0; while (!validAnswer) { Console.WriteLine("And how much dough did you bring today?"); validAnswer = int.TryParse(Console.ReadLine(), out bank); if (!validAnswer) Console.WriteLine("Please enter digits only, no decimals."); } //Console.WriteLine("How much dough did you bring today?"); //int 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" || answer == "yez") { Player player = new Player(playerName, bank); //initialize constructor player.Id = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"C:\Users\seatt\Desktop\C#_Projects\log.txt", true)) { file.WriteLine(player.Id); } Game game = new TwentyOneGame(); game += player; player.isActivelyPlaying = true; while (player.isActivelyPlaying && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); Console.ReadLine(); return; } catch (Exception ex) { Console.WriteLine("An error occurred. Please contact your system admin."); UpdateDbWithException(ex); Console.ReadLine(); return; } } game -= player; Console.WriteLine("Thanks for playing!"); } Console.WriteLine("Feel free to look around the casino {0}. Bye for now!", playerName); Console.ReadLine(); }