Computer Programming

Computer Programming » An Actual Computer Program » Writing a Dice Game of Craps

Writing a Dice Game of Craps

The game of craps will demonstrate the programming fundamentals. We are going to use a modified version of the game as follows:
A new shooter begins his roll. This is known as the come out roll. If the shooter rolls a 7 or 11 you win. If the shooter rolls a 2, 3 or 12, you lose. If the shooter rolls any other number, that number becomes the point number. The shooter must roll that number again before a seven is rolled. If that happens, you win. If a seven is rolled before the point number is rolled again, you lose.

Start Visual Basic as we had done before. In the future you can learn about how to switch to another project, but for now we will simply start again from the beginning for this program. We are going to create a new project. This time we are going to write a real application that you can use.


Name it WindowsApplication2. Remember that this name is only important for us as we write the code, and it does not reflect the name that the application actually has to have when people are using it. We will change the name of the executable later on to something that lets people know what they are going to be running.


We will start with a blank program. It is possible to use another program that we had developed as a starting point so that it is not necessary to begin from nothing each time. Depending on the application, you may use another program as a foundation.


Select the form window. Remember to notice that you will get the small squares around the outside of the form to help signify to you that it has been correctly selected. Since the Form is the main window of our application, we want to set it up to be the main window of our application.


Change the text property of the window to Craps. The Text property is a common property, but when it is part of a Form, the text is the title of the window. It will signify Craps as our main application, which also means that when someone minimizes the window, the name Craps will be displayed in its minimized state. You want your user to pick out your application from all the other applications that may be running.


Our main form window title changes to Craps. Feel free to choose whatever title you want. For the most part, when we change a text property it does not impact the code that we write. Remember that we can name the windows and the buttons, and then in order to interact with them we need to know the name of the item. The text property of the item is only something that is shown to the user which is totally different from its name. The text property is for the user. The name of the item is for us programmers.


⇐ Prev Chapter
Saving the executable program

Next Chapter ⇒
Adding a welcome message

Computer Programming for Everyday People
Michael Bigrigg

Amazon eBook

Powered by w3.css