Ross Sheppard High School
Computer Programming 20
Student Learning Guide
The Paper, Rocks, Scissors Program


  When you have finished this project, you will be able to:
use the randomizer to load a graphic
create a simple interactive game
use the If . . . Then . . . ElseIf statement
change properties within the program code
use the GoTo statement

describe the following terms:

  • If . . . Then . . . ElseIf
  • GoTo
  1. Create a new folder called PRS on your personal drive.

  2. The illustration below shows the visual implementation for the Paper, Rock, Scissors program.



    The Paper, Rock, Scissors Program

    The Paper, Rock, Scissors program is an electronic representation of the game you may have played as a child. In this case, however, you are programming a game to be played against the computer. The PRS game requires the user to select a choice of Paper, Rock, or Scissors by pressing the appropriate button. The user's choice is displayed on the program. When the Play button is pressed, Visual Basic randomly generates the computer's choice, which is also displayed. Based on the two selections, Visual Basic determines whether it is a win, loss, or tie and displays the appropriate message. In addition, there is a Clear button if the user wants to start over, as well as a Quit button.

  3. Before you begin, you need the three graphics that you will use in the Paper, Rock, Scissors Program. The three graphics are shown below:


    Copy the three bitmap (bmp) images from the handout folder to your personal drive.

  4. Start a new Standard.exe project in Visual Basic. Save this project as prjPRSProgram and the form as frmPRSProgram in the PRS Program folder.

  5. Use the table below to create the Visual Implementation of the Array Program:

    Objects Table
    Object Property Setting
    Form Name frmPRS
      Caption The Paper, Rock, Scissors Program
    TextBox Name txtUserChoice
      Font MS Sans Serif Bold 18
      Alignment Center
      Text Make it blank
      Multiline True
    TextBox Name txtCompChoice
      Font MS Sans Serif Bold 18
      Alignment Center
      Text Make it blank
      Multiline True
    TextBox Name txtStatus
      Font MS Sans Serif Bold 18
      Alignment Center
      Text Make it blank
      Multiline True
    TextBox Name txtUserMem
      Font MS Sans Serif Bold 18
      Alignment Center
      Text Make it blank
      Multiline True
      Visible False
    CommandButton Name btnPaper
      Caption Paper
    CommandButton Name btnRock
      Caption Rock
    CommandButton Name btnScissors
      Caption Scissors
    CommandButton Name btnPlay
      Caption Play
    CommandButton Name btnExit
      Caption Exit
    CommandButton Name btnClear
      Caption Clear
    PictureBox Name picPaper
      Picture paper.bmp
    PictureBox Name picRock
      Picture rock.bmp
    PictureBox Name picScissors
      Picture scissors.bmp
    PictureBox Name picUserPic
    PictureBox Name picCompPic

    Note: for the purpose of enhancing the Visual Implementation of the PRS Program, you may change other properties such as StartUp Position, background color, etc.

  6. Now that you have completed the Visual Implementation of the PRS Program, you can begin to create the code.

  7. Write the pseudo-code for the Paper, Rock, Scissors program on your Program Documentation form.

  8. In the General_Declarations area of the program, add the programmer information, the Option Explicit code and declare the uChoice variable.

    :

  9. Create the code for the Exit button.

  10. The next code that you will write is the code that is associated with the CommandButton btnPaper. When this button is pressed, the following events take place:
  11. The code for the btnPaper is:



  12. Save your project and run it. Try pressing the Paper button to ensure the program works. Do the Rock and Scissors button work? Explain your answer.

  13. Write the code for the Rock and Scissors buttons.

  14. Save your project and run it. Ensure the three user buttons work.

  15. Next, you will create the code of the CommandButton btnPlay. When the Play button is pressed the following events take place: Later, you will add more code to the btnPlay CommandButton, but for now you only want to get it to make a choice and display that choice.

  16. Add the following code to the CommandButton btnPlay_Click():



  17. You should be able to explain the purpose of each line of code.

  18. Save your project and run it. When you click play, the computer's choice should be displayed in the proper boxes.

  19. In the Paper, Rock, Scissors program design, you are required to indicate whether the play is a win, loss, or tie. You will write the code for this part of the program next.

  20. In order to determine whether there is a win, loss, or tie, you need to write down the possible scenarios. Create a chart on your Program Documentation form that indicates the possible scenarios.
    Does your scenario chart look like this?

  21. First of all, remember the following rules in the PRS game:
  22. Now, write the code that determines the win, loss, or tie status and displays that in the TextBox txtStatus:



  23. Notice that you have used a new procedure called ElseIF. This procedure is used when you require a number of conditions within the If . . . Then statement.

  24. Save your project and run it. Play the PRS game by first selecting the user choice then pressing the Play button. Try several different games to see how your program works.

  25. There is one problem with the PRS game: what happens when the user presses play without selecting a choice? The program does not work properly when this happens.

  26. As a good programmer, you must anticipate that a player might do this and create a procedure in your program to deal with this. For your PRS program, you will create code that will cause a message to display that says "Please make a choice" and then beep.

  27. The code for this is:



  28. Save your project and run it. Try running it without making a user choice. What is wrong with the program?

  29. You can change the properties of any object on a Visual Basic Form by writing code to do so. In the case of the TextBox txtCompChoice, you set the Font property to MS Sans Serif Bold 18, which is fine for a short phrase such as "Paper". However, when you try to display something longer, such as "Please make a choice", there is not enough room to display it in the TextBox. You could change the size of the TextBox or the Font property, but then it would not match the TextBoxes on the form. So, you can modify the properties when the program runs.

  30. First of all, define the Font as a variable:



  31. Add the following code to the btnPlay CommandButton:



  32. Notice the two GoTo statements. GoTo is used when you need the program to skip some code if one condition is true, or run that code if the condition is not true.

  33. In the case of your code, the statement reads, "If the user has not made a choice, beep, change the font size, display the message "Please make a choice", then go to the Finish section. If this statement is not true, then set the font and go to the Continue section.

  34. Now it is time to define the Finish and Continue sections so Visual Basic knows where to GoTo.

  35. Type the following code just above the comment that describes what the btnPlay does:



    This tells Visual Basic where the Continue section starts.


  36. Type Finish: just above the End Sub statement for the CommandButton btnPlay.

  37. Save your program and run it. The Play button should work properly both when you do not make a selection, and when you do.

  38. The next task you need to do is to write the code for the CommandButton btnClear. When pressed, this button should:
  39. Write the code for the CommandButton brnClear and try it out. Did it work?

  40. One final task: change the Visible property of the TextBox txtUserMem to False. This is so the TextBox will not show when the program is run.

  41. Save the project and test it.

  42. Change the properties and locations of the objects on the form to create a pleasing layout for the user.

  43. When you are finished, send an email to your teacher asking that this project be marked.

  44. Click here to see the marking guide for this project.

  45. In the next lesson, you will revisit the PRS Program to make it more user friendly.


© 1998-2000 N.F. Mathew, EdD
File name: PRS.htm
Last updated on October 23, 2000