C# Method - Applications

 

Rock, Paper, Scissors - Design

When a rock, paper, or scissors is selected by the user those buttons become unenabled. The winner is displayed. In order to play another round, the reset button is pressed which enables the three buttons (and disables the reset button).

No global variables are used in this program. Rather, after the user makes his or her selection, and after the computer makes its selection, that data is passed to other methods to determine the winner.

A hierarchy chart shows how this is done.

On the top row we will see the buttons. These are the events we program when one of these buttons is pressed. But rather than code all this stuff into those buttons we break the program down into smaller, easier to manage, functions or methods that do specific tasks. This way, we don’t have to know how to flip buttons, or play game, or clear labels or make the computer selection, or even determine the winner. At least not at once. Rather each of those pieces is a smaller method or program snippet which we program individually.

Rock, Paper, Scissors - Programming

This time we are going to finish Rock, Paper, Scissors. This is the programming piece. We’ll also use the debugger here to follow how the methods are passing data from one to another. There’s even one method in this that will use the “passing by reference” technique.

I also want to mention the fact that we’ll be using a hierarchy chart to help us code this program. The hierarchy chart functions as a check list. Basically, it is a series of buttons at the top of the page followed by all the methods that these buttons will call. This is a classic in breaking complicated things down into smaller, easy to understand functions.