private void InitGame() { game = new GuessingGame(); Input = ""; GameOn = true; Message = "Guess a number between 1 and 100"; }
static void Main() { // TODO: // a) implement the functionality of selecting a game type when first entering the program // b) decouple USER I/O from guessing logic // c) after the console view module is separated = add a web app I/O view GuessingGame game = new GuessingGame(); game.Start(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmGuessNumber()); GuessingGame GuessThatNumber = new GuessingGame(); }
public void GuessingGame_RunSimulation_GuessWrong() { var actualNumber = 10; var numberOfGuesses = 9; GuessingGame = new GuessingGame(actualNumber, numberOfGuesses); var actualMessage = GuessingGame.RunSimulation(numberOfGuesses); var expectedMessage = $"You guessed {numberOfGuesses}. The number you're trying to guess is greater than {numberOfGuesses}"; Assert.AreEqual(expectedMessage, actualMessage); }
public void GuessingGame_RunSimulation_GuessCorrectly() { var actualNumber = 1054; var numberOfGuesses = 9; GuessingGame = new GuessingGame(actualNumber, numberOfGuesses); var actualMessage = GuessingGame.RunSimulation(actualNumber); var expectedMessage = $"Congratulations!!! it took you {GuessingGame.GuessCount} guesses to guess the number {actualNumber}"; Assert.AreEqual(expectedMessage, actualMessage); }
public void after_a_lot_of_correct_guesses_all_remaining_result_should_be_game_over() { var x = new GuessingGame(73, 4); Assert.AreEqual(GuessResult.Higher, x.Guess(5)); Assert.AreEqual(GuessResult.Higher, x.Guess(50)); Assert.AreEqual(GuessResult.Higher, x.Guess(52)); Assert.AreEqual(GuessResult.Success, x.Guess(73)); Assert.ThrowsException <Exception>(() => x.Guess(5)); Assert.ThrowsException <Exception>(() => x.Guess(5)); }
public IActionResult RandomNumber(int Num) { int generatedNumber = Convert.ToInt32(HttpContext.Session.GetInt32("RandomNumber")); String result = GuessingGame.getResult(Num, generatedNumber); HttpContext.Session.SetString("Result", result); HttpContext.Session.SetInt32("UserGuess", Num); HttpContext.Session.SetString("View", "Game/RandomNumber/Post"); return(RedirectToAction(nameof(RandomNumber))); }
private int PlayTheGuessingGame() { var guesser = new PsychicGuesser(); var game = new GuessingGame(); var lastResult = -1; while (lastResult != 0) { lastResult = game.Guess(guesser.MakeAGuess(lastResult)); } return(game.Guesses); }
public static void Main(string[] args) { GuessingGame userTry = new GuessingGame(); int secret = userTry.GenerateSecret(); int userInput; Console.WriteLine("I have a number between 1 and 1000." + "( " + secret + " )"); Console.WriteLine("Please enter your first guess: "); userInput = Convert.ToInt32(Console.ReadLine()); userTry.CheckGuess(userInput, secret); }
public void TestMethod1() { int magicNumber = 42; GuessingGame game = new GuessingGame(100, new NotActuallyRandom(magicNumber)); var expectedTooHigh = "Too High!"; var expectedTooLow = "Too low!"; var expectedGotIt = "You guessed it!"; Assert.AreEqual(expectedGotIt, game.guessANumber(42)); Assert.AreEqual(expectedTooHigh, game.guessANumber(43)); Assert.AreEqual(expectedTooLow, game.guessANumber(41)); }
public IActionResult RandomNumber() { if (HttpContext.Session.GetString("View") != null && (HttpContext.Session.GetString("View")).CompareTo("Game/RandomNumber/Post") == 0) { ViewBag.Result = HttpContext.Session.GetString("Result"); ViewBag.UserGuess = HttpContext.Session.GetInt32("UserGuess"); ViewBag.GeneratedNumber = HttpContext.Session.GetInt32("RandomNumber"); } int generatedNumber = GuessingGame.getRandomNum(); HttpContext.Session.SetInt32("RandomNumber", generatedNumber); return(View()); }
public void number_of_guesses_should_not_change() { var x = new GuessingGame(73, 5); Assert.AreEqual(5, x.GuessesLeft); x.Guess(10); Assert.AreEqual(4, x.GuessesLeft); x.Guess(10); Assert.AreEqual(4, x.GuessesLeft); x.Guess(10); Assert.AreEqual(4, x.GuessesLeft); }
public void normal_play_that_ends_with_correct_guess() { var x = new GuessingGame(73, 4); Assert.AreEqual(4, x.GuessesLeft); Assert.AreEqual(GuessResult.Higher, x.Guess(50)); Assert.AreEqual(3, x.GuessesLeft); Assert.AreEqual(GuessResult.Lower, x.Guess(80)); Assert.AreEqual(2, x.GuessesLeft); Assert.AreEqual(GuessResult.Success, x.Guess(73)); Assert.AreEqual(1, x.GuessesLeft); }
public IActionResult Index() { int rndNumber = GuessingGame.RandomNumber(); ViewBag.Rnd = rndNumber; HttpContext.Session.Clear(); if (string.IsNullOrEmpty(HttpContext.Session.GetString(SessionKeyRndNumber))) { HttpContext.Session.SetInt32(SessionKeyRndNumber, rndNumber); HttpContext.Session.SetString(SessionKeyTryNumber, ""); } return(View()); }
public ActionResult GuessGame(int GuessNum = 0) { List <int> Guesses = new List <int>(); List <string> OldGuesses = new List <string>(); string msg = ""; string oldmsg = ""; if (Session["Guesses"] != null) { Guesses = (List <int>)Session["Guesses"]; } Session["Guesses"] = Guesses; Guesses.Add(GuessNum); if (Session["oldGuesses"] != null) { OldGuesses = (List <string>)Session["oldGuesses"]; } Session["oldGuesses"] = OldGuesses; if (Session["Random"] != null) { if (GuessNum <= 0 || GuessNum >= 101) { msg = "You not guessing within the limit range!"; Guesses.Remove(Guesses.Last()); } else if (GuessNum == Convert.ToInt32(Session["Random"])) { msg = "You guessed Correct with " + Guesses.Count + " guesses. New number drawn."; oldmsg = "The number was " + Session["Random"] + ". It took you " + Guesses.Count + " attempts to guess right."; OldGuesses.Add(oldmsg); Session["Random"] = GuessingGame.RandomNumber(); Guesses.Clear(); } else if (GuessNum < Convert.ToInt32(Session["Random"])) { msg = "You guessed to low. You have guessed " + Guesses.Count + " times so far."; } else if (GuessNum > Convert.ToInt32(Session["Random"])) { msg = "You guessed to high. You have guessed " + Guesses.Count + " times so far."; } } Session["msg"] = msg; return(View()); }
public void GuessingGame_RunSimulation_GuessesOverTheLimit() { var actualNumber = 1054; var numberOfGuesses = 9; GuessingGame = new GuessingGame(actualNumber, numberOfGuesses); for (int i = 0; i < numberOfGuesses; i++) { GuessingGame.RunSimulation(numberOfGuesses); } var actualMessage = GuessingGame.RunSimulation(numberOfGuesses); var expectedMessage = $"You guessed {numberOfGuesses}. I'm sorry but you have run out of guesses to guess {actualNumber}. Better luck next time!"; Assert.AreEqual(expectedMessage, actualMessage); }
public void normal_play_that_ends_with_game_over() { var x = new GuessingGame(46, 4); Assert.AreEqual(4, x.GuessesLeft); Assert.AreEqual(GuessResult.Lower, x.Guess(66)); Assert.AreEqual(3, x.GuessesLeft); Assert.AreEqual(GuessResult.Lower, x.Guess(50)); Assert.AreEqual(2, x.GuessesLeft); Assert.AreEqual(GuessResult.Higher, x.Guess(30)); Assert.AreEqual(1, x.GuessesLeft); Assert.AreEqual(GuessResult.Fail, x.Guess(35)); Assert.AreEqual(0, x.GuessesLeft); }
public void FirstPlayerIsLoserSecondPlayerIsWinner() { Player firstPlayer = new Player() { FPPG = 1 }; Player secondPlayer = new Player() { FPPG = 99 }; List <Player> players = new List <Player> { firstPlayer, secondPlayer }; IEnumerable <Player> HighestPlayers = GuessingGame.GetPlayerWithHighestFPPG(players); Assert.True(!HighestPlayers.Contains(firstPlayer), "First player was a winner"); Assert.True(HighestPlayers.Contains(secondPlayer), "Second player was a loser"); }
public void TwoPlayersTie() { Player firstPlayer = new Player() { FPPG = 1 }; Player secondPlayer = new Player() { FPPG = 1 }; List <Player> players = new List <Player> { firstPlayer, secondPlayer }; IEnumerable <Player> HighestPlayers = GuessingGame.GetPlayerWithHighestFPPG(players); //everyone is a winner! Assert.True(HighestPlayers.Contains(firstPlayer) && HighestPlayers.Contains(secondPlayer), "One of the players was a loser"); }
public IActionResult OnPost() { game = new GuessingGame( (int)HttpContext.Session.GetInt32(RAND_NUMBER) ); //get user's guess from form string guess = Request.Form["UserGuess"]; int guessInt; if (int.TryParse(guess, out guessInt)) { Result = game.Guess(guessInt); } else { Result = "Please enter a valid integer"; } return(Page()); }
public IActionResult Index(int guessNumber, string autoRestart) { var rndNumber = HttpContext.Session.GetInt32(SessionKeyRndNumber); var tryNumbers = HttpContext.Session.GetString(SessionKeyTryNumber); string tryingNumbers = ""; string startAgain = ""; tryNumbers = GuessingGame.TryNumbers(tryNumbers, guessNumber); HttpContext.Session.SetString(SessionKeyTryNumber, tryNumbers); GuessingGame guessingGame = new GuessingGame(); string guessResult = guessingGame.Guess(guessNumber, (int)rndNumber); if (guessResult == "Congratulation!") { tryingNumbers = "The number was " + rndNumber + " and your guessing numbers are: " + tryNumbers; // Button when finish guessing ViewBag.Restart = "Show"; // Autorestart when finish guessing startAgain = "You can now continue guessing on a new number."; int getRndNumber = GuessingGame.RandomNumber(); HttpContext.Session.SetInt32(SessionKeyRndNumber, getRndNumber); HttpContext.Session.SetString(SessionKeyTryNumber, ""); // Redirect to run HttpGet //return RedirectToAction("Index", "GuessingGame"); } ViewBag.Index = guessResult + autoRestart; ViewBag.Numbers = tryingNumbers; ViewBag.Again = startAgain; ViewBag.Rnd = rndNumber; return(View()); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our views from the layout resource, FirstPlayerButton = FindViewById <ImageButton>(Resource.Id.FirstPlayerImageButton); FirstPlayerNameTextView = FindViewById <TextView>(Resource.Id.FirstPlayerNameTextView); SecondPlayerButton = FindViewById <ImageButton>(Resource.Id.SecondPlayerImageButton); SecondPlayerNameTextView = FindViewById <TextView>(Resource.Id.SecondPlayerNameTextView); FirstPlayerButton.Click += FirstPlayerButton_Click; SecondPlayerButton.Click += SecondPlayerButton_Click; players = await jsonClient.ReadPlayers(); guessingGame = new GuessingGame(players); SetUpUiForNextRound(); }
private void btnCheck_Click(object sender, EventArgs e) { myGuess = new GuessingGame(inputGuess); myGuess.checkGuess(); inputGuess = Convert.ToInt32(txtGuess.Text) }
public static void Main() { Console.WriteLine("Play My Game:"); string response = Console.ReadLine(); GuessingGame newGuessingGame = new GuessingGame(response); }
private void EndGame() { ShowAlert("You Win!", "Close Dialog to try again."); guessingGame = new GuessingGame(players); SetUpUiForNextRound(); }
public void StartNumberGuessingGame() { GuessingGame numberGuessing = new GuessingGame(); numberGuessing.Start(); }
public void should_return_gameover_when_no_guesses_left() { var x = new GuessingGame(73, 1); Assert.AreEqual(GuessResult.Fail, x.Guess(5)); }
public void should_return_correct_when_correct_guess() { var x = new GuessingGame(73, 4); Assert.AreEqual(GuessResult.Success, x.Guess(73)); }
public ActionResult GuessGame() { Session["Random"] = GuessingGame.RandomNumber(); return(View()); }
public void OnGet() { game = new GuessingGame(); HttpContext.Session.SetInt32(RAND_NUMBER, Number); }