private void MainForm_Load(object sender, EventArgs e) { // firstly, show the Players form PlayersForm form = new PlayersForm(); // if we added at least one player and pressed OK, then start: if (form.ShowDialog() == DialogResult.OK) { statistics = form.GameStats; // create new game object game = new BlackjackGame(); // initialize visualizer gamevisualizer = new CardTableVisualizer(game); gamevisualizer.PrepareGraphics(this.Width, this.Height, CreateGraphics()); // initialize controller: // pass the game and visualizer objects // and the FixGameResults() function as the function that will be called when the game's over gamecontroller = new CardTableController(game, gamevisualizer, FixGameResults); // set the list of active players for a new game game.SetPlayerList(form.GetActivePlayers()); // start new game NewGame(); } else { Close(); } }
private void MainForm_Load(object sender, EventArgs e) { // firstly, show the Players form PlayersForm form = new PlayersForm(); // if we added at least one player and pressed OK, then start: if (form.ShowDialog() == DialogResult.OK) { statistics = form.GameStats; // create new game object game = new BlackjackGame(); // initialize visualizer gamevisualizer = new CardTableVisualizer(game); gamevisualizer.PrepareGraphics(this.Width, this.Height, CreateGraphics()); // initialize controller: // pass the game and visualizer objects // and the FixGameResults() function as the function that will be called when the game's over gamecontroller = new CardTableController(game, gamevisualizer, FixGameResults); // set the list of active players for a new game game.SetPlayerList( form.GetActivePlayers() ); // start new game NewGame(); } else { Close(); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (BlackjackGame game = new BlackjackGame()) { game.Run(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); BlackjackGame.Activity = this; var g = new BlackjackGame(); SetContentView(g.Window); g.Run(); }
static void Main(string[] args) { IBlackjackGame game = new BlackjackGame(); game.Setup(); game.Play(); }
public override void FinishedLaunching(UIApplication app) { // Fun begins.. game = new BlackjackGame (); game.Run (); //MediaLibrary lib = new MediaLibrary(); //object result = lib.Playlists; }
public override void FinishedLaunching(UIApplication app) { // Fun begins.. game = new BlackjackGame(); game.Run(); //MediaLibrary lib = new MediaLibrary(); //object result = lib.Playlists; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //BlackjackGame.Activity = this; var g = new BlackjackGame(); //SetContentView(g.Window); SetContentView((View)g.Services.GetService(typeof(View))); g.Run(); }
public static void RunInteractiveTest() { Console.Write ("\n\nRunning Interactive Test Console...\n" + CardGame.ConsoleLine('~') + "\n"); CardGame currentGame = new BlackjackGame(); //DojoCardGame currentGame = new PokerGame(); //DojoCardGame currentGame = new SpadesGame(); //DojoCardGame currentGame = new HeartsGame(); bool playAgain = true; Console.WriteLine ("Press enter to play " + currentGame.Name + "..."); Console.Read (); //< Function waits for the user to input a character. Debug.WriteLine ("\n\n" + CardGame.ConsoleLine('#') + "Starting a game of " + currentGame.Name); /** Play-again loop. A play-again loop goes in a loop where the user is asked if they want to play again. The user can enter "hit", "hold", "exit", or "quit". The code for the game */ while (playAgain && currentGame.PlayGameInConsole ()) // Main game loop. { Console.WriteLine ("Do you want to play again?\n" + "Type yes to continue, or no to quit."); bool inputValid = false; while (!inputValid) { String input = Console.ReadLine ().ToLower (); /* If the user wants to continue, they need to type the letter y, or else we need to exit the program loop. We need to convert the input to lower case letters just in case someone capitalizes any of the letters. */ if (input == "yes") // Keep playing. { // playAgain is current true. inputValid = true; } else if (input == "no") //< Then exit the play-again loop. { playAgain = false; inputValid = true; } else { Console.Write ("\nPlease type yes to continue, or no to quit.\n"); } } } }
static void Main(string[] args) { //BlackjackSettings settings = SaveDefaultSettings(); BlackjackSettings settings = LoadSettingsFromFile("settings.xml"); BlackjackGame game = new BlackjackGame(settings); //ConsoleBlackjackPlayer player = new ConsoleBlackjackPlayer() { Game = game }; var handsToPlay = 100000000L; var player = new BasicStrategyPlayer(handsToPlay); game.Play(new [] { player }); Console.WriteLine("Profit: {0}%", Math.Round((player.Profit / settings.MinimumBet / (decimal)handsToPlay) * 100m, 2)); }
static void Main(string[] args) { try { using (BlackjackGame game = new BlackjackGame()) { game.Run(); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } }
static void Main(string[] args) { try { using (BlackjackGame game = new BlackjackGame()) { game.Run(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } }
static void Main(string[] args) { Random random = new Random(); CardFactory cardFactory = new CardFactory(); Deck deck = new Deck(cardFactory, random); Player player = new Player(); Dealer dealer = new Dealer(deck); HandsFactory handsFactory = new HandsFactory(); BlackjackGame game = new BlackjackGame(dealer, player, handsFactory); GameView gameView = new GameView(); GameController gameController = new GameController(game, gameView); MainController mainController = new MainController(gameController, gameView); mainController.RunGame(); }
/// <summary> /// The CardTableVisualizer constructor. /// It tries to load the Cards.dll assembly and each card from it. If some problems occur the corresponding message is shown and the program is terminated. /// It sets the main parameters of the class /// </summary> /// <param name="blackjackgame">The game to visualize</param> public CardTableVisualizer( BlackjackGame blackjackgame ) { // attach the game object game = blackjackgame; // PlayersHighlight = NewGameHighlight = false; // try to load the Cards.dll assembly and all cards from it try { Assembly cardsAssembly = Assembly.LoadFrom("Cards.dll"); ResourceManager rm = new ResourceManager("Cards.Properties.Resources", cardsAssembly); Bitmap b = (Bitmap)rm.GetObject("back"); cardBack = new Bitmap(b, drawCardWidth, drawCardHeight); // resize the bitmap for (int i = 0; i < 52; i++) { b = (Bitmap)rm.GetObject("_" + i); cardImages[i] = new Bitmap(b, drawCardWidth, drawCardHeight); // resize the bitmap } } catch (Exception) { System.Windows.Forms.MessageBox.Show( "Some problems occured with the Cards.dll or a card image from it" ); System.Windows.Forms.Application.Exit(); } // ----------------- set up the coordinates of all visual objects on the card table dealerCoords.X = 500; dealerCoords.Y = 50; for (int i = 0; i < BlackjackGame.MAX_PLAYERS; i++) { playerCoords[i].X = 30 + (15 + drawCardWidth) * i; playerCoords[i].Y = 320; hitrects[i] = new Rectangle(25 + 105 * i, 285, 30, 30); standrects[i] = new Rectangle(60 + 105 * i, 285, 30, 30); doublerects[i] = new Rectangle(95 + 105 * i, 285, 30, 30); } for (int i = 0; i < BlackjackGame.DECKS_COUNT; i++) { shoesCoords[i].X = 10 + (10 + drawCardWidth) * i; shoesCoords[i].Y = 50; } }
/// <summary> /// The CardTableVisualizer constructor. /// It tries to load the Cards.dll assembly and each card from it. If some problems occur the corresponding message is shown and the program is terminated. /// It sets the main parameters of the class /// </summary> /// <param name="blackjackgame">The game to visualize</param> public CardTableVisualizer(BlackjackGame blackjackgame) { // attach the game object game = blackjackgame; // PlayersHighlight = NewGameHighlight = false; // try to load the Cards.dll assembly and all cards from it try { Assembly cardsAssembly = Assembly.LoadFrom("Cards.dll"); ResourceManager rm = new ResourceManager("Cards.Properties.Resources", cardsAssembly); Bitmap b = (Bitmap)rm.GetObject("back"); cardBack = new Bitmap(b, drawCardWidth, drawCardHeight); // resize the bitmap for (int i = 0; i < 52; i++) { b = (Bitmap)rm.GetObject("_" + i); cardImages[i] = new Bitmap(b, drawCardWidth, drawCardHeight); // resize the bitmap } } catch (Exception) { System.Windows.Forms.MessageBox.Show("Some problems occured with the Cards.dll or a card image from it"); System.Windows.Forms.Application.Exit(); } // ----------------- set up the coordinates of all visual objects on the card table dealerCoords.X = 500; dealerCoords.Y = 50; for (int i = 0; i < BlackjackGame.MAX_PLAYERS; i++) { playerCoords[i].X = 30 + (15 + drawCardWidth) * i; playerCoords[i].Y = 320; hitrects[i] = new Rectangle(25 + 105 * i, 285, 30, 30); standrects[i] = new Rectangle(60 + 105 * i, 285, 30, 30); doublerects[i] = new Rectangle(95 + 105 * i, 285, 30, 30); } for (int i = 0; i < BlackjackGame.DECKS_COUNT; i++) { shoesCoords[i].X = 10 + (10 + drawCardWidth) * i; shoesCoords[i].Y = 50; } }
static void Main(string[] args) { BlackjackSettings settings = LoadSettingsFromFile("settings.xml"); BlackjackGame game = new BlackjackGame(settings); var handsToPlay = 100000000L; //BasicStrategyPlayer basic = new BasicStrategyPlayer(handsToPlay); //var table = ActionTable.FromStrategy(basic); //var player = basic; //var player = new ConsoleBlackjackPlayer() { Game = game }; //var player = new WizardSimpleStrategy(handsToPlay); //var player = new ActionTablePlayer(table, handsToPlay) { Print = true }; var player = new SimpleFiveCountPlayer(handsToPlay); game.Play(new [] { player }); Console.WriteLine("Profit: {0:N2}%", player.Profit / settings.MinimumBet / (decimal)handsToPlay * 100m); }
public override void FinishedLaunching(MonoMac.Foundation.NSObject notification) { game = new BlackjackGame(); game.Run (); }
static void Main() { game = new BlackjackGame(); game.Run(); }
public PlayerController(Hand hand, BlackjackGame gameInstance) { Hand = hand; GameInstance = gameInstance; }
static void Main(string[] args) { Console.WriteLine("Welcome to the Grand Hotel and Casino. Please tell 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.ReadLine(); return; } bool valid = false; int bank = 0; while (!valid) { Console.WriteLine("What is your buy-in?"); valid = int.TryParse(Console.ReadLine(), out bank); if (!valid) { Console.WriteLine("Please enter a whole number using digits only."); Console.ReadLine(); } } Console.WriteLine("Blackjack table changing $" + bank + "!!!!"); Console.WriteLine("Hello, {0}. Shall we begin?", playerName); string answer = Console.ReadLine().ToLower(); if (answer == "yes" || answer == "yep" || answer == "sure" || answer == "yeah" || answer == "y") { Player player = new Player(playerName, bank); Game game = new BlackjackGame(); 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. Goodbye for now."); Console.ReadLine(); }
public override void FinishedLaunching(MonoMac.Foundation.NSObject notification) { game = new BlackjackGame(); game.Run(); }
static void Main(string[] args) { //========== CASINO NAME const string casinoName = "Grand Hotel and Casino"; //========== LOG FILE string logDir = Directory.GetCurrentDirectory() + @"\logs"; string logFile = logDir + @"\log.txt"; if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } string logTxt = string.Format("========== BLACKJACK LOG ==========\n{0}\n", DateTime.Now); File.WriteAllText(logFile, logTxt); //========== GAME SETUP Console.BackgroundColor = ConsoleColor.DarkGreen; Console.ForegroundColor = ConsoleColor.Yellow; Console.Clear(); Console.WriteLine("\n===================================================\n=====( Welcome to the {0} )=====\n===================================================\n", casinoName); Game game = new BlackjackGame(); //========== ADD PLAYERS const int maxPlayers = 7; bool addPlayers = true; string playerName; while (addPlayers && game.Players.Count < maxPlayers) { Console.WriteLine("\nPlayer, what is your name?"); playerName = Console.ReadLine(); playerName = playerName[0].ToString().ToUpper() + playerName.Substring(1); //===== ADMIN ENTRY if (playerName == "Admin") { List <ExceptionEntity> exceptions = ReadExceptions(); foreach (var e in exceptions) { Console.Write(e.Id + " | "); Console.Write(string.Format("{0} | ", e.ExceptionType)); Console.Write(string.Format("{0} | ", e.ExceptionMessage)); Console.WriteLine(string.Format("{0} \n", e.TimeStamp)); } Console.Read(); return; } //===== PLAYER ENTRY Player player = new Player(playerName); // asks for player bank if not provided if (player.Balance > 0) { Console.WriteLine("Hello {0}. Would you like to join a game of Blackjack right now?", playerName); if (Console.ReadLine().ToLower().Contains("y")) { game += player; Console.WriteLine("-->{0} added to game.", playerName); } } if (game.Players.Count < maxPlayers) { Console.WriteLine("\nIs someone else joining today?"); if (Console.ReadLine().ToLower().Contains("n")) { addPlayers = false; } } } //========== PLAY - continue to play rounds until NO players are actively playing or have a balance > 0 while (game.Players.Count > 0) { //----- Play game try { game.Play(); } catch (FraudException e) { UpdateDbException(e); Console.WriteLine("SECURITY! Throw this person out."); Console.ReadLine(); return; } catch (Exception e) { UpdateDbException(e); Console.WriteLine("ERROR. Please contact your system administrator."); Console.WriteLine("ERROR: " + e.Message); Console.ReadLine(); return; } //----- Player removal List <Player> removals = new List <Player>(); removals = game.Players.Where(x => !x.ActivelyPlaying || x.Balance == 0).ToList(); foreach (Player player in removals) { game -= player; } } //========== GAME OVER Console.WriteLine("\n===Thank you for playing."); Console.WriteLine("Feel free to look aroung the casino. Bye for now."); //========== TESTS ========== //string str1 = "Here is some text.\nMore on a new line.\tHere is some after a tab."; //File.WriteAllText(logFile, str1); //string txt = File.ReadAllText(logFile); //Console.WriteLine(txt); //===== CREATE DECK //Deck deck = new Deck(); //===== SHUFFLE DECK //deck.Shuffle(times: 4, true); //===== lambda functions //int count = deck.Cards.Count(x => x.Face == Face.Ace); //Console.WriteLine(count); //List<Card> newList = deck.Cards.Where(x => x.Face == Face.Ace).ToList(); //foreach (Card card in newList) { Console.WriteLine(card.Face); } //List<int> numList = new List<int>() { 1,2,3,535,342,23 }; //int sum = numList.Sum(); //Console.WriteLine(sum); //int sumPlus = numList.Sum(x => x + 1); //Console.WriteLine(sumPlus); //int max = numList.Max(); //Console.WriteLine(max); //int min = numList.Min(); //Console.WriteLine(min); //int sumBig = numList.Where(x => x > 100).Sum(); //Console.WriteLine(sumBig); //Console.WriteLine(numList.Where(x => x > 100).Sum()); //===== Overloaded operator //Game game = new BlackjackGame() { Name = "BlackJack", Dealer = "Doc Holliday", Players = new List<Player>() }; //Player p1 = new Player() { Name = "Wyatt Earp" }; //Player p2 = new Player() { Name = "Jesse James" }; //game = game + p1 + p2; //game.ListPlayers(); //game = game - p2; //game.ListPlayers(); //deck.ListCards(loop: "foreach"); //Dealer dealer = new Dealer(); //dealer.Name = "Alex"; //Console.WriteLine(dealer.Name); // can get/set public properties when base class is not explicitly public //Game game2 = new Game(); // can't create a new object based on an abstract class //===== HOLD OPEN - till enter is pressed Console.ReadLine(); }
static void Main() { // Welcome message Console.WriteLine("LET'S PLAY BLACKJACK!\n"); // Get player name 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; } // Get player starting amount bool validAnswer = false; int purse = 0; while (!validAnswer) { Console.WriteLine("\nHow much money are you starting with?"); Console.Write("$"); validAnswer = int.TryParse(Console.ReadLine(), out purse); if (!validAnswer) { Console.WriteLine("Please enter a whole number"); } } // Ask to start game Console.WriteLine("\nHello, {0}! \nReady to get started? (y or n)", playerName); string ready = Console.ReadLine().ToLower(); // Initialize game if player is ready if (ready == "yes" || ready == "y") { // Create new player object Player player = new Player(playerName, purse); player.ID = Guid.NewGuid(); using (StreamWriter file = new StreamWriter(@"C:\Users\daved\Desktop\log.txt", true)) { file.WriteLine(player.ID); } //Create new game object Game game = new BlackjackGame(); // Add player to list of game players game += player; // Set player's playing status to "Active" player.IsActive = true; // Skip a line for presentation Console.WriteLine(); // Start game loop and continue until player quits or runs out of money while (player.IsActive && player.Balance > 0) { try { game.Play(); } catch (FraudException ex) { Console.WriteLine(ex.Message); UpdateDbWithException(ex); return; } catch (Exception ex) { Console.WriteLine("Something went wrong."); UpdateDbWithException(ex); return; } } // Remove player from list of game players when done game -= player; // Ending message Console.WriteLine("Thanks for playing!"); } // Goodbye message and end of program Console.WriteLine("Please come back when you are ready to play."); Console.Read(); }
/// <summary> /// Controller's constructor sets the objects passed as parameters /// </summary> /// <param name="blackjackgame">The game object</param> /// <param name="gamevisualizer">The visualizer object</param> /// <param name="handler">The GameOver event handler (caller's function - in our case it's in the MainForm)</param> public CardTableController( BlackjackGame blackjackgame, CardTableVisualizer gamevisualizer, GameOverHandler handler ) { game = blackjackgame; cardtable = gamevisualizer; GameOver += handler; }
static void Main() { game = new BlackjackGame(); game.Run (); }
/// <summary> /// Controller's constructor sets the objects passed as parameters /// </summary> /// <param name="blackjackgame">The game object</param> /// <param name="gamevisualizer">The visualizer object</param> /// <param name="handler">The GameOver event handler (caller's function - in our case it's in the MainForm)</param> public CardTableController(BlackjackGame blackjackgame, CardTableVisualizer gamevisualizer, GameOverHandler handler) { game = blackjackgame; cardtable = gamevisualizer; GameOver += handler; }