Read the Case Study about the algorithm for the Word Guess game on pages 146 & 147.
Pages 148 & 149 contain the basic code for the Word Guess game. You will be turning this into a Hangman game by adding code to keep track of wrong answers and adding pictures for each wrong answer until the user runs out of guesses.
Put a picture box on the form.
You will, also, need to add have a String variable and a label to keep track of wrong guesses. (See the grade program.)
Dim wrong As Integer = 0
Dim missedLetters As String = ""
Dim correctGuess As Boolean = False
The variable correctGuess is assigned True after the line the line
If SECRET_WORD.Chars(letterPos) = Char.ToUpper(letterGuess) Then
correctGuess=True
After the For-Next loop that inserts the letter, you will need to insert code to check if correct= False. If it is false, add one to wrong and add the wrong letter to missedLetters, and show the missedLetters in a label.
Assign correctGuess=False
Have If-ElseIf conditions for each number assigned to wrong, to assign different images in the picture box.
Pages 148 & 149 contain the basic code for the Word Guess game. You will be turning this into a Hangman game by adding code to keep track of wrong answers and adding pictures for each wrong answer until the user runs out of guesses.
Put a picture box on the form.
You will, also, need to add have a String variable and a label to keep track of wrong guesses. (See the grade program.)
Dim wrong As Integer = 0
Dim missedLetters As String = ""
Dim correctGuess As Boolean = False
The variable correctGuess is assigned True after the line the line
If SECRET_WORD.Chars(letterPos) = Char.ToUpper(letterGuess) Then
correctGuess=True
After the For-Next loop that inserts the letter, you will need to insert code to check if correct= False. If it is false, add one to wrong and add the wrong letter to missedLetters, and show the missedLetters in a label.
Assign correctGuess=False
Have If-ElseIf conditions for each number assigned to wrong, to assign different images in the picture box.
chapter_5_loops_and_string_methods_review.docx |
The String Class – page 138
String – anything inside " "
Dim name as String
name = "Matthew"
lblName.Text = "His name is " & name
Write a program and call it StringPractice.
Button
1. Use an InputBox to enter a phrase or word
2. Show the phrase in a label
3. Show the number of letters in the phrase
4. Use an input box to choose a word to look for
5. Use indexOf to tell the location of a letter or word in the phrase
On pages 139 and 140 you will find methods that are part of the String class.
ToUpper – changes all the letters to all caps
ToLower – changes all the letters to lowercase
Replace – replaces an old string with a new string)
phrase = phrase.Replace(search, replace)
Add to the assignment above:
Dim String variables for phrase, search and replace.
Use InputBoxes to enter a word to search for and a word to replace it with.
Replace the search word with the replace word in the phrase.
Show the new phrase in a label.
************************************************************************
Read pages 129-134 in the book.
Download and read the Loop notes.
On page 134 there is an AverageBowlingScore program. Use the algorithm to write a program that will average grades. Do not copy the code on the next page. We can make it much more simple.
1) The GradeAverage program will allow you to enter as many grades as you want until you enter a flag to stop. Inside a do-while loop you will enter grades, count the grades, add each grade to the sum, check for the largest and the smallest grade. After the loop, you will get the average, using sum and count, show the average, the largest and smallest grades.
The equation sum = sum + grades adds the grade to sum each time through the loop.
You can use a String to show a list of words or numbers using the & to put them together.
Example:
Dim list as String = ""
Inside the loop use the equation:
list= list & grade & ", "
After the loop:
Me.lblList.Text = "Your numbers are: " & list
will show Your numbers are: 99, 88, 77 , 85
2) Write the UniqueRandomNumbers program on page 136.
String – anything inside " "
Dim name as String
name = "Matthew"
lblName.Text = "His name is " & name
Write a program and call it StringPractice.
Button
1. Use an InputBox to enter a phrase or word
2. Show the phrase in a label
3. Show the number of letters in the phrase
4. Use an input box to choose a word to look for
5. Use indexOf to tell the location of a letter or word in the phrase
On pages 139 and 140 you will find methods that are part of the String class.
ToUpper – changes all the letters to all caps
ToLower – changes all the letters to lowercase
Replace – replaces an old string with a new string)
phrase = phrase.Replace(search, replace)
Add to the assignment above:
Dim String variables for phrase, search and replace.
Use InputBoxes to enter a word to search for and a word to replace it with.
Replace the search word with the replace word in the phrase.
Show the new phrase in a label.
************************************************************************
Read pages 129-134 in the book.
Download and read the Loop notes.
On page 134 there is an AverageBowlingScore program. Use the algorithm to write a program that will average grades. Do not copy the code on the next page. We can make it much more simple.
1) The GradeAverage program will allow you to enter as many grades as you want until you enter a flag to stop. Inside a do-while loop you will enter grades, count the grades, add each grade to the sum, check for the largest and the smallest grade. After the loop, you will get the average, using sum and count, show the average, the largest and smallest grades.
The equation sum = sum + grades adds the grade to sum each time through the loop.
You can use a String to show a list of words or numbers using the & to put them together.
Example:
Dim list as String = ""
Inside the loop use the equation:
list= list & grade & ", "
After the loop:
Me.lblList.Text = "Your numbers are: " & list
will show Your numbers are: 99, 88, 77 , 85
2) Write the UniqueRandomNumbers program on page 136.