How to Create a Simple Game Using Microsoft Visual Basic
How to Create a Simple Game Using Microsoft Visual Basic
1.0 INTRODUCTION
Microsoft Visual Basic .NET is a popular programming language created for developers
who want to develop their applications quickly. Visual Basic is categorized as a RAD
(Rapid Application Development) language because it offers a graphical approach to
creating user interfaces and its coding syntax is easy to learn. As such, beginners often
benefit from learning to program in VB first, then gradually moving on to more advanced
languages. The instructions provided below are created for people who are familiar with
the Microsoft Windows operating system, but have little or no prior programming
language experience.
In this tutorial, you be introduced to the basic concepts of programming. Topics that will
be covered include designing forms and creating variables. By following the step-by-step
instructions provided below, you will learn how to create a word guessing game.
If you have not programmed before, be prepared to spend half an hour on this tutorial. If
you have prior programming experience, expect to spend around twenty minutes. You
must have Visual Basic installed on your computer before starting. I recommend
purchasing Visual Basic .NET if you expect to get deeper into programming, but
alternatively you can download Visual Basic 2005 Express for free. The instructions
below may not work if you use any version other than Visual Basic .NET.
In order to create the word guessing game, you must carefully follow the steps explained
below.
2.1.1 First, open Visual Basic .NET by double-clicking on its icon in the Start
menu.
2.1.2 Once Visual Basic has been opened, click File on the menu bar. Now,
click on the submenu New and press Project .
Matthew Leung
2.1.3 When the New Project dialog box pops up, you will be presented with
different types of projects that can be created. Choose the Windows
Application within the Visual Basic Projects folder. Next, type in the
new name for your project (name this project wordGuess ), and choose a
location to save it. Click on the OK button.
2.2.1 The goal now is to create a user interface for your users, so that they can
easily interact with your program. Click and drag TextBox from the
Toolbox bar to your form. Refer to Figure 2 for the approximate location
of where you should place the TextBox. Check to see that the name of
this element is Textbox1 (look in the Properties inspector) and the text is
set to blank.
2.2.2 Click and drag Label from the Toolbox to the form. Click on this Label,
copy it (Ctrl-C), and paste it (Ctrl-V) six times. Your labels now have text
such as Label1 , Label2 , and so on. The text in Label1 to Label5
should be deleted. Click on Label1, delete the Text value in the
Properties inspector, and change the Name value to box1 . Repeat this
step for the other four labels, naming them box2 , box3 , and so on.
Change the Text Value of Label6 to Number of Incorrect Guesses= .
Finally, change the Text value of Label7 to 0 and the Name value to
guess. Refer to Figure 2 to see that you have changed the Text and
Name values correctly.
Matthew Leung
2.2.3 Click and drag a Button from the Toolbox. Change its Text value to
Guess .
Figure 2: The interface of nameGuess. Note: The borders on the labels have been
added for clarity only.
In this phase, you will begin to code your application. Copy and paste the code as
directed below. The code is explained in Figure 4 and Figure 5
2.3.1. Double-click on the Guess button. You will now see the code window
(refer to Figure 3)
2.3.2. Type this first code snippet into the code window. Note that our secret
word for users to guess is hello (in lowercase). If they guess correctly, a
letter will show up.
Matthew Leung
2.3.3. Insert the new code in Figure 5 into your existing code.
2.4.1 You are now ready to test your program. In the menu bar, click on
Debug and then Start . Alternatively you can hit F5 on your keyboard.
If your program appears, you have succeeded in creating your first Visual
Basic .NET game. If nothing appears, check that all the code has been
copied correctly.
3.0 CONCLUSION
As you can tell, using Visual Basic to create programs is not difficult. There are three
main phases to application development in Visual Basic: creating the user interface,
adding the code, and testing your program. Once your program in complete, it is ready to
be used by you or anyone you choose to give it to. Of course, you can go always back to
Visual Basic and make modifications as you see fit.