Flylib.com

Books Software

 
 
 

Microsoft Visual Basic 2005 Express Edition Programming for the Absolute Beginner - page 68


SUMMARY

In this chapter, you learned how to work with variations of the Do and For loops . You also learned how to set up a While loop. You learned how to use loops to collect and process user input and to process the contents of arrays and controls, such as the ListBox . In addition, you learned about endless loops and how to use variations of the Exit keyword to break out of loops. On top of all this, you created the Dice Poker game.

Now, before you move on to Chapter 8, "Enhancing Code Structure and Organization," and start learning how to work with procedures, take a few extra minutes and improve the Dice Poker game by completing the following challenges.



CHALLENGES

  1. Add a menu system to the Dice Poker game, including the following menu items under the File menu: Roll Dice, Roll Again, Stick, and Quit. Also add a Help menu, and provide the player with access to pop-up windows that display the rules of the game and information about the game and its developer.

  2. Modify the Dice Poker game so that it tracks and displays information about the number of games that have been played , won, and lost.

  3. Enhance the Dice Poker game so that it looks for two of a kind but doesn't add or subtract any dollars from the player's account for this tying hand.

  4. Enhance the Dice Poker game so that it looks to see if the player's hand has two pairs and awards the player a dollar for this winning hand.



Chapter 8: Enhancing Code Structure and Organization

OVERVIEW

Whether you have realized it or not, every application that you have developed so far in this book has relied on procedures to organize and store program code. In this chapter, you will learn how to create your own custom procedures. You will learn how to create Sub and Function procedures and will understand the difference between the two. You will also learn how to pass data to your procedures for processing and how to return data from Function procedures. In addition, you will get plenty of chances to create and work with custom procedures when you create this chapter's game project, the Hangman game.

Specifically, you will learn how to:

  • Organize the programming logic that makes up your applications into procedures in order to make them easier to develop and maintain

  • Create custom procedures

  • Pass and return data to and from procedures

  • Streamline your applications by placing reusable code within procedures

  • Develop procedures that can process optional data



PROJECT PREVIEW: THE HANGMAN GAME

In this chapter's project, you will apply your new knowledge of how to work with different types of procedures to the development of the Hangman game. Figures 8.1 to 8.7 show examples from the Hangman game, demonstrating its functionality and overall execution flow.

image from book
Figure 8.1: When first started, the game displays a graphic showing an empty hangman's gallows and a series of underscore characters representing the secret word.

image from book
Figure 8.2: As the game progresses, each correct guess is displayed at the top of the window, and a visual record of every letter guessed is displayed at the bottom of the window.

image from book
Figure 8.3: The game prevents the player from making the same letter guess more than once.

image from book
Figure 8.4: The game only permits the player to enter one letter at a time.

image from book
Figure 8.5: The game prevents the player from entering numeric input.

image from book
Figure 8.6: The game congratulates the player when the secret word has been successfully guessed.

image from book
Figure 8.7: If the player fails to guess the secret word within six guesses, the game is lost and the picture of the hangman's gallows is updated to show a full hangman image.

By the time you have created and run this game, you will have demonstrated your under standing of how to create custom Sub and Function procedures and how to use them to improve the overall organization and maintenance of your Visual Basic applications.