Building a Guessing Game | C# | Tutorial 19

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2017
  • Source Code - www.giraffeacademy.com/program... This video is one in a series of videos where we'll be looking at programming in C#. The course is designed for new programmers, and will introduce common programming topics using the C# language.
    Throughout the course we'll be looking at various topics including variables, arrays, getting user input, loops, conditionals, object orientation and much more.

ความคิดเห็น • 35

  • @janaewelsh8056
    @janaewelsh8056 4 ปีที่แล้ว +20

    I've been watching an rewatching this series to get a better grasp on the basics of C# and just wanted to say that you're course has been a huge, huge help. I'd have to say it's the best course on C# for beginners that I've found on TH-cam, Skillshare, Udemy or any other site. Thanks so much for putting these videos up! :)

    • @upcom1ng116
      @upcom1ng116 2 ปีที่แล้ว +4

      I was so willing to pay for the basic course and look through entire list of Udemy and couldn't really find anything decent and funny enough I found his channel and it's FREE!

  • @pulcifyfn2919
    @pulcifyfn2919 4 ปีที่แล้ว +11

    literally love you, helped me finish my game when i was stuck

  • @jasonatkinson2549
    @jasonatkinson2549 5 ปีที่แล้ว +5

    Hey Mike! I'm loving the tutorials, thank you! I took your idea from this tutorial and played with it a little bit. I figure you're too busy to check it out but I just wanted to say thanks for the hard work... you're definitely making a difference.

  • @scottisitt
    @scottisitt 4 ปีที่แล้ว +2

    Great video! Easy to follow. Thanks, Mike!

  • @joyride9353
    @joyride9353 4 ปีที่แล้ว +5

    Hello Mike. I noticed a difference in the code for this video and what is on your website.
    while(!guess == secretWord && !outOfGuesses) Is what the website shows, but brings back an error.
    while(guess != secretWord && !outOfGuesses) works correctly and is what is shown in the video.
    Thank you for your tutorials. I am a beginner and these videos are extremely helpful.

    • @saadalsabagh4862
      @saadalsabagh4862 3 ปีที่แล้ว

      Thank you so much Alex for pointing out this errors. I spent a lot of time to figure this out.
      Thank you Mike for this great tutorial!

  • @DelphicRachel
    @DelphicRachel ปีที่แล้ว

    I benefitted a lot from this course, but there's just one thing I was wondering; how do you create a guessing game where the program selects a random string variable from an array, and then sets that as the word that you have to guess?
    Thanks so much for this amazing tutorial :)

  • @ShadesGameSource
    @ShadesGameSource 3 ปีที่แล้ว +3

    I managed to write the code below using a do while loop.
    I'm also reading a textbook on C# as I go through your videos, so I was able to incorporate a couple of things that haven't been mentioned in your videos (so far). =)
    string answer = "giraffe";
    string guess = "";
    int guessCounter = 5;
    do
    {
    Console.WriteLine("You have {0} guesses left.", guessCounter);
    Console.WriteLine("What is the most powerful animal in the universe?");
    guess = Console.ReadLine();
    Console.Write("
    "); //noob line break implementation!
    guessCounter -= 1;
    }
    while (guess != answer && guessCounter > 0);
    if (guess == answer)
    {
    Console.WriteLine("
    You won!~");
    }
    else
    {
    Console.WriteLine("
    You died!");
    }
    Console.ReadLine();

  • @simplyjemelah8276
    @simplyjemelah8276 2 ปีที่แล้ว

    hi do you have a word guessing game with ArrayList and StringBuilder example?

  • @MyMrdouchebag
    @MyMrdouchebag 3 ปีที่แล้ว

    how do you make it where from the console player 1 enters a random word then player 2 guesses what it is?

  • @azorailke6057
    @azorailke6057 2 ปีที่แล้ว

    I went ahead and added a counter like this :
    int guessRemaining = guessLimit - guessCount;
    Console.Write("You have " + guessRemaining + " guess(es) remaining. Guess the secret word: ");
    guess = Console.ReadLine();
    guessCount++;
    It worked out well! 😺 I even let the user input how many guesses they wanted and did not let them specify a negative number or over 10. The code for that part looks messy though.

  • @AnimeRPG1
    @AnimeRPG1 3 ปีที่แล้ว

    Added an array ( 03:11 ) to account for lower and uppercase (1st letter only):
    static void Main(string[] args)
    {
    //LESSON 17
    Console.WriteLine("LESSON 17");
    Console.WriteLine("");
    string[] secretWord = new string [2];
    secretWord[0] = "Author";
    secretWord[1] = "author";
    string guessWord = "";
    {
    }
    while (guessWord != secretWord[0] && guessWord != secretWord[1])
    {
    Console.Write("Enter a guess for the secret word: ");
    guessWord = Console.ReadLine();
    }
    Console.WriteLine("You Win!");
    Console.ReadLine();
    }

  • @flourishajiboye706
    @flourishajiboye706 2 ปีที่แล้ว

    I have a little question
    In the code, your put the guessLimit at 3 meaning that you only want the user to answer 3 times. But under the while loop in the if statement you put the condition as (guessCount < guessLimit).
    guessCount keeps incrementing it self, and well I don't know how to say this but I'll try, i expected that the comdition would be (guessCount

  • @thecatch4648
    @thecatch4648 ปีที่แล้ว

    To make the user input case-insensitive you can use '.ToLower()'
    Like this "guess = Console.ReadLine().ToLower();"

  • @Matstarx25
    @Matstarx25 3 ปีที่แล้ว

    Theres a problem with the game though. It's lacking an if-statement before the loop begins.
    Because if you get the word correct in 1st try, you are still prompted to guess again untill you hit 3/3 guesses.

    • @AnimeRPG1
      @AnimeRPG1 3 ปีที่แล้ว

      Didn't do that for me:
      static void Main(string[] args)
      {
      //LESSON 17
      Console.WriteLine("LESSON 17");
      Console.WriteLine("");
      string[] secretWord = new string [2]; //Use an array to acount for Author or author being typed.
      secretWord[0] = "Author";
      secretWord[1] = "author";
      string guessWord = "";
      int guessCount = 0;
      int guessLimit = 3;
      bool outOfGuesses = false;
      {
      }
      while (guessWord != secretWord[0] && guessWord != secretWord[1] && !outOfGuesses)
      {
      if (guessCount < guessLimit)
      {
      Console.Write("Enter a guess for the secret word: ");
      guessWord = Console.ReadLine();
      guessCount++;
      }
      else
      {
      outOfGuesses = true;
      }
      }
      if (outOfGuesses)
      {
      Console.WriteLine("You lose! You ran out of guesses.");
      }
      else
      {
      Console.WriteLine("You Win!");
      }
      Console.ReadLine();
      }

  • @AnimeRPG1
    @AnimeRPG1 3 ปีที่แล้ว +3

    12:36 Final product using an Array:
    static void Main(string[] args)
    {
    //LESSON 17
    Console.WriteLine("LESSON 17");
    Console.WriteLine("");
    string[] secretWord = new string [2]; //Use an array to account for Author or author being typed.
    secretWord[0] = "Author";
    secretWord[1] = "author";
    string guessWord = "";
    int guessCount = 0;
    int guessLimit = 3;
    bool outOfGuesses = false;
    {
    }
    while (guessWord != secretWord[0] && guessWord != secretWord[1] && !outOfGuesses)
    {
    if (guessCount < guessLimit)
    {
    Console.Write("Enter a guess for the secret word: ");
    guessWord = Console.ReadLine();
    guessCount++;
    }
    else
    {
    outOfGuesses = true;
    }
    }
    if (outOfGuesses)
    {
    Console.WriteLine("You lose! You ran out of guesses.");
    }
    else
    {
    Console.WriteLine("You Win!");
    }
    Console.ReadLine();
    }

  • @tehminashehryar7802
    @tehminashehryar7802 ปีที่แล้ว

    You can watch a very simple tutorial to develop puzzle game in C# for beginners at th-cam.com/play/PLHGJljNavL-PZ6P7w1IhZAZhZPp-9f_2L.html

  • @AITakesYourJob
    @AITakesYourJob 2 ปีที่แล้ว

    Tried to do "do" loop. I'm newbie, but it kinda worked.
    string secretword = "ass";
    string guess = "";
    int tries = 0;
    bool outoftries = false;
    do
    {
    if (tries < 3)
    {
    Console.WriteLine("Your guess: ");
    guess = Console.ReadLine();
    tries++;
    }
    else
    {
    outoftries = true;
    }
    }
    while (guess != secretword && !outoftries);
    if (outoftries) { Console.WriteLine("You failed"); }
    if (guess == secretword) { Console.WriteLine("You won!"); }

    • @AITakesYourJob
      @AITakesYourJob 2 ปีที่แล้ว

      here from next tutorial, also tried to create this game using "for" loop, but i have no idea if i did it right, it just works.
      string secretword = "ass";
      string guess = "";
      int tries;
      for (tries = 0; tries < 3; tries++)
      {
      Console.WriteLine("Your guess: ");
      guess = Console.ReadLine();
      if (secretword == guess) { Console.WriteLine("You won"); break; }

      }
      if (tries == 3)
      { Console.WriteLine("You failed"); }

  • @gn26422458
    @gn26422458 5 ปีที่แล้ว +2

    Just a beginner, isn't this code cleaner?
    // MY CODE
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace Giraffe1
    {
    class Program
    {
    static void Main(string[] args){
    int count = 0;
    do {
    string secretWord = "apple";
    Console.WriteLine("Yo what should be the secret word?");
    string answer = Console.ReadLine();
    count++;
    if (secretWord == answer)
    {
    Console.WriteLine("you're right!");
    break;
    }
    } while (count < 3);
    Console.ReadLine();
    }
    }
    }
    // MY CODE

    • @ROYALGAMERJAMES
      @ROYALGAMERJAMES 4 ปีที่แล้ว +3

      yeah but this video is not about just making the game its about to leaning to coding by these commands etc........

    • @axyegaming6128
      @axyegaming6128 4 ปีที่แล้ว

      Your code is cleaner even mine is the cleanest but he is trying to summarize previous lessons in one video

  • @user-zm5sk4ht9c
    @user-zm5sk4ht9c 4 ปีที่แล้ว

    Can't you just use a simple break; instead of !outOfGuesses?

    • @upcom1ng116
      @upcom1ng116 2 ปีที่แล้ว

      You can use break; with if and else condition but not in parameter. Nature of while condition is Boolean only.

  • @darthvader44
    @darthvader44 3 ปีที่แล้ว

    Hello sir i created this game with do wile loop
    string word = "adi";
    string ans="";
    int guess= 0;
    int trial =1;
    bool outofguess = false ;
    Console.WriteLine("Press enter to start");
    Console.ReadLine();
    do
    {

    if (guess

  • @mambafamkdmambamkdfa1077
    @mambafamkdmambamkdfa1077 3 หลายเดือนก่อน

    static void Main()
    {
    string secretWord = "apple";
    string guess = " ";
    int guessCount = 0;
    int guessLimit = 3;
    bool outOfGuesses = false;
    do
    {
    if (guessCount < guessLimit)
    {
    Console.WriteLine("Etner your guess");
    guess = Console.ReadLine();
    guessCount++;
    }
    else
    {
    outOfGuesses = true;
    }
    }
    while (guess != secretWord && !outOfGuesses);
    if (outOfGuesses)
    {
    Console.WriteLine("You Lose!!");
    }
    else
    Console.WriteLine("You WIN!!!!");

  • @MadBunnyRabbit
    @MadBunnyRabbit 5 ปีที่แล้ว

    I would argue that having a game you can't exit from within is a worse design decision than the player having infinite guesses :]

  • @garylake9317
    @garylake9317 ปีที่แล้ว

    Sorry, but nobody would ever win that game.