rock paper scissors game c# windows form code example
Example: rock paper scissors game c# windows form
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; } } }}