Rock paper scissors is a hand game played by two or more people. The players usually count aloud to four or speak the name of the game (e.g. "Rock Paper Scissors!" ), each time either raising one hand in a fist and swinging it down on the count or holding it behind. On the third count (saying, "Shoot!" or "Go!" "Scissors!" or "Bo!"), the players change their hands into one of three gestures, which they then "throw" by extending it towards their opponent. This program is written using the C# programming language.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
computerpicturebox.BackgroundImage = PictureBox1.BackgroundImage;
PlayerPictureBox.BackgroundImage = PictureBox1.BackgroundImage;
}
private void rockPicturebox_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
int computerChoice;
PlayerPictureBox.BackgroundImage = rockPicturebox.BackgroundImage;
computerChoice = randomGenerator.Next(1, 4);
switch (computerChoice)
{
case 1: computerpicturebox.BackgroundImage = rockPicturebox.BackgroundImage;
winnerLabel.Text = " TIE ";
break;
case 2:
computerpicturebox.BackgroundImage = paperPicturebox.BackgroundImage;
winnerLabel.Text = " Computer wins because paper covers rock ";
break;
case 3:
computerpicturebox.BackgroundImage = scissorsPictureBox.BackgroundImage;
winnerLabel.Text = " Player wins because rock breaks scissors ";
break;
}
}
private void paperPicturebox_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
int computerChoice;
PlayerPictureBox.BackgroundImage = paperPicturebox.BackgroundImage;
computerChoice = randomGenerator.Next(1, 4);
switch (computerChoice)
{
case 1:
computerpicturebox.BackgroundImage = rockPicturebox.BackgroundImage;
winnerLabel.Text = " Payer wins because paper covers rock ";
break;
case 2:
computerpicturebox.BackgroundImage = paperPicturebox.BackgroundImage;
winnerLabel.Text = " TIE ";
break;
case 3:
computerpicturebox.BackgroundImage = scissorsPictureBox.BackgroundImage;
winnerLabel.Text = " Computer wins because scissors cut paper ";
break;
}
}
private void scissorsPictureBox_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
int computerChoice;
PlayerPictureBox.BackgroundImage = scissorsPictureBox.BackgroundImage;
computerChoice = randomGenerator.Next(1, 4);
switch (computerChoice)
{
case 1:
computerpicturebox.BackgroundImage = rockPicturebox.BackgroundImage;
winnerLabel.Text = " Computer wins because rock breaks scissors ";
break;
case 2:
computerpicturebox.BackgroundImage = paperPicturebox.BackgroundImage;
winnerLabel.Text = " Player wins because scissors cut paper ";
break;
case 3:
computerpicturebox.BackgroundImage = scissorsPictureBox.BackgroundImage;
winnerLabel.Text = " TIE ";
break;
}
}
}
}