public Form1() { InitializeComponent(); newGame = new GuessingGame(); lblGuessResult.Text = ""; newGame.StartRound(); }
static bool TryGetGame(string[] args, out GuessingGame game) { game = null; if (args.Length < 2) { Console.Error.WriteLine($"ERROR: Insufficient arguments."); return(false); } int min, max; if (!int.TryParse(args[0], out min)) { Console.Error.WriteLine($"ERROR: {args[0]} is not an integer."); return(false); } if (!int.TryParse(args[1], out max)) { Console.Error.WriteLine($"ERROR: {args[0]} is not an integer."); return(false); } game = new GuessingGame(min, max); return(true); }
////creates a random number between 1 and 100 and stores it in a global ////variable that can be used throughout the program //public static Random randNum = new Random(); //int rand = randNum.Next(1, 101); public Form1() { InitializeComponent(); GuessingGame gg = new GuessingGame(); this.Controls.Add(gg); gg.Location = new Point((this.Width - gg.Width) / 2, (this.Height - gg.Height) / 2); gg.Show(); }
public static void Main(string[] args) { GuessingGame guessingGame = new GuessingGame(); Console.WriteLine("Guess number from {0} to {1}", GuessingGame.lowInt, GuessingGame.upperInt - 1); bool gameOver = false; do { Console.WriteLine("Enter number:"); int playerNumber = int.Parse(Console.ReadLine()); try { if (guessingGame.Game(playerNumber)) { Console.WriteLine("You are guessed"); gameOver = true; } else { Console.WriteLine("Try again"); } } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Invalid number: " + e.Message); } Console.WriteLine("Remaining tries: " + guessingGame.Tries + "\n"); if (guessingGame.Tries <= 0) { break; } } while (!gameOver); if (!gameOver) { Console.WriteLine("Game over"); } }
static void Main(string[] args) { GuessingGame game = new GuessingGame(); Console.WriteLine("I am thinking of a number between " + GuessingGame.LowerBoundary + " and " + GuessingGame.UpperBoundary); bool gameOver = false; do { Console.WriteLine("Enter a number"); int guessedNumber = int.Parse(Console.ReadLine()); try { if (game.Guess(guessedNumber)) { Console.WriteLine("You Win! The hidden number was " + guessedNumber); gameOver = true; } else { Console.WriteLine("Incorrect Guess! You failed to guess the hidden number."); } } catch (ArgumentOutOfRangeException ex) { Console.WriteLine("Invalid Guess! " + ex.Message); } Console.WriteLine("Number of tries remaining: " + game.Tries + "\n"); if (game.Tries <= 0) { break; } } while (!gameOver); if (!gameOver) { Console.WriteLine("Out of tries! Game over!"); } }
static void Main(string[] args) { var game = new GuessingGame(); game.Play(); }
public Form1() { InitializeComponent(); GuessingGame gg = new GuessingGame(); this.Controls.Add(gg); }