We fill the list full of underscores so we can show the player how many letters they have to guess. You can use an underscore and a space afterward if you like a gapped display, but either works fine.
The foreach loop goes through each letter within GuessDisplay and prints them on the screen. We use Console. Write instead of WriteLine so it displays all on one line. We then do a WriteLine to put the cursor down a line, then wait for user input. Do you see that ToUpper makes an appearance here? We start with an if clause that says: if ThisAnswer. Unfortunately, Contains only tells us if it contains the letter, not where the letter is. We want to know where the letters are, so we can reveal them to the player through GuessDisplay.
Feel free to use the shorthand version if you like! If the answer does contain the letter, that means the player is correct. First, we tell the player they got the right answer. Then we turn the input into a char, so we can easily use it for the function coming up. We use a for loop to go through each letter of the answer list and check it against the input. If the input matches the current letter being inspected, it updates the GuessDisplay to let the player know where the letters are.
This states that if the GuessDisplay does not contain underscores, the player has successfully guessed every letter in the puzzle. At the end, we close out the if statement for when the player gets a correct answer, and starts an else statement. If you played it now, you should be able to guess all the letters, but when you get the correct answer, the game just stops working.
After the HasWon loop, we check to see if the player won. If they did, we let them know, then wait for a key press. When a key is pressed, we safely close out the software. It plays through, loops around until the player gets the word right, then congratulates the player when they win and closes on key press.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters. Copy link. I just wanted to ask which encryption application did you use for the words? You can use the decrypt function from the source code.
Im using Dev c and im getting an error on line 31 when trying to compile. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Pepijn Kramer Pepijn Kramer 5 5 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related
0コメント