ROCK, PAPER, SCISSORS (Graphical User Interface) APPLICATION

  1. New Project -- “Windows Forms Application” – Name (RockPaperScissors)
  2. SAVE ALL! Save every 10-15 minutes. Always use SAVE ALL!
  3. View the Solution Explorer (view, solution explorer)
  4. Change the following properties of the form:
  5. backcolor (choose any color you want)
  6. title bar (text property) change to “Rock Paper Scissors”
  7. icon (choose any icon you want, find icons in our class folder)
  8. From the toolbox add three Buttonsand a MenuStrip.
  9. Buttons
  10. Name the three buttons btnRock, btnPaper, btnScissors.
  11. Change the font to a larger font.
  12. Change the Text Property of the three buttons to display ROCK, PAPER, and SCISSORS.
  13. TextAlign to MiddleCenter.
  14. Import Images from Folder into buttons.
  15. Stretch the Image on the Button.
  16. From the toolbox, add a MenuStrip to your form. The MenuStrip will appear in the bottom left corner in the system tray. On the top left tab of the MenuStrip, type “File.” Below File, type each of the lines: About, Exit. To the right type: Stats.
  17. From the ToolBox add six PictureBoxes.
  18. Click the Arrow on the Top-Right of the PictureBox to Stretch the Image.
  19. Name the PictureBox picRockPlayer.
  20. Change the Visible Property to False
  21. Load the Image of the Rock.
  22. Create a PictureBox for Rock, Paper, and Scissors for both the Player and the Computer.
  23. Move all three pictures for the Player and for the Computer on top of each other.
  24. From the ToolBox add three PictureBoxes.
  25. Click the Arrow on the Top-Right of the PictureBox to Stretch the Image.
  26. Name the PictureBox picPlayer.
  27. Change the Visible Property to False
  28. Load the Image for the Player winning.
  29. Create a PictureBox for the Computer winning and for ties.
  30. Move all three pictures for the Player and for the Computer on top of each other.

  1. Double Click on the Form to enter the Code and Code your program.
  2. Most code is in each of the 3 buttons. However, also code each item in the MenuStrip.
  3. Begin by double-clicking on your form. You will need to add the following code in the general declarations section of the form after Public Class Form1.cs

// Declare variables

int wins = 0;

int losses = 0;

int ties = 0;

string player = "None";

string computer = "None";

c. Return to the design of the form and double click on the ‘Rock’ button. Then, add the following code to the button “btnRock”:

privatevoid btnRock_Click(object sender, EventArgs e)

{

// Player chooses rock

player = "rock";

// Show the appropriate PictureBox and Hide the others.

picRockPlayer.Show();

picPaperPlayer.Hide();

picScissorsPlayer.Hide();

turn(); // Call the Turn Method to let the computer choose

winner(); // Call the Winner Method to determine the winner.

}

d. Repeat the steps in ‘c’ for btnPaper and btnScissors.

e. Create the turn method after the last Method.

privatevoid turn()

{

// Generate a random obkect (choice) for the computer.

Random choice = newRandom();

// Pick a random number

int compChoice = choice.Next(3);

// Give the computer a choice

if (compChoice == 0)

{

computer = "Rock";

// Show the appropriate PictureBox and Hide the others.

picRockComputer.Show();

picPaperComputer.Hide();

picScissorsComputer.Hide();

}

elseif (choice == 1)

{

computer ="Paper";

// Show the appropriate PictureBox and Hide the others.

picRockComputer.Hide();

picPaperComputer.Show();

picScissorsComputer.Hide();

}

else

{

computer = "Scissors";

// Show the appropriate PictureBox and Hide the others.

picRockComputer.Hide();

picPaperComputer.Hide();

picScissorsComputer.Show ();

}

f. Create the winner method after the last method

private void winner()

{

// Figure out the winner

if (computer == player)

{

ties++;

// Show the PictureBox for ties and Hide the others.

picTie.Show();

picPlayer.Hide();

picComputer.Hide();

}

elseif ((computer == "Paper"& player == "Scissors") || (computer == "Scissors"& player

== "Rock") ||(computer == "Rock" & player == "Paper"))

{

wins++;

// Show the PictureBox for ties and Hide the others.

picTie.Hide();

picPlayer.Show();

picComputer.Hide();

}

else

{

losses++;

// Show the PictureBox for ties and Hide the others.

picTie.Hide();

picPlayer.Hide();

picComputer.Show();

}

}

g. Finally, code the MenuStrip. Click each item to open thecode window for the item:
privatevoidaboutToolStripMenuItem_Click(object sender, EventArgs e)

{

MessageBox.Show("by Dean R. White”);

}

privatevoidstatsToolStripMenuItem_Click(object sender, EventArgs e)

{

MessageBox.Show("Wins = “ + wins.ToString()+ “\nLosses = “ + losses.ToString() + “\nTies =

“ + ties.ToString());

}

privatevoidexitToolStripMenuItem_Click(object sender, EventArgs e)

{

this.Close();

}

11.Run and test your program. Click Rock, Paper, or Scissors. You are playingthe computer!