Hybridoma Technology ( Production , Purification , and Application )
Β
I have been working on this ROCK, PAPER, SCISSORS project for the pa.pdf
1. I have been working on this ROCK, PAPER, SCISSORS project for the past 6 days or so, and
it's still giving me absolute fits. I have created two pictureBox controls in the designer, and here
is my current source
code:
namespace ROCK_PAPER_SCISSORS_GAME_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
sim iComputer As Integer = 0;
Private iWins As Integer = 0;
Private iDraw As Integer = 0;
Private iLose As Integer = 0;
private void rockButton_Click(object sender, EventArgs e)
{
{
playerLabel.Text = "Rock";
PicBox.Image = "Rock.bmp";
int iComputer = rand.Next(3);
computerLabel.Text = "Paper";
scoreLabel.Text = "You lose!";
iLose = iLose + 1;
}
if (iComputer == 2)
{
pic.Image = "Rock.bmp";
computerLabel.Text = "Rock";
scoreLabel.Text = "Draw!";
iDraw = iDraw + 1;
}
4. LabelWins1.Text = iWins;
LabelDraw1.Text = iDraw;
LabelLose1.Text = iLose;
}
}
private void resetButton_Click(object sender, EventArgs e)
{
iLose = 0;
iDraw = 0;
iWins = 0;
LabelWins1.Text = iWins;
LabelDraw1.Text = iDraw;
LabelLose1.Text = iLose;
playerLabel.Text = "";
computerLabel.Text = "";
picComputer.Image = Nothing;
picPlayer.Image = Nothing;
scoreLabel.Text = "";
}
}
private void DisplayImages(int randomImage, PictureBox picBox)
// Get the current Application working directory.
string imgPath = Environment.CurrentDirectory
+ "picBoxImage";
// Use switch case to display the respective images in PictureBox.
switch (randomImage)
{
case 1:
// picBox.ImageLocation =
// imgPath + "Rock.BMP";
// break;
picBox.Image = ROCK_PAPER_SCISSORS_GAME_2.
Properties.Resources.Rock;
break;
case 2:
5. // picBox.ImageLocation =
// imgPath + "Paper.BMP";
// break;
picBox.Image = ROCK_PAPER_SCISSORS_GAME_2.
Properties.Resources.Paper;
break;
case 3:
// picBox.ImageLocation =
// imgPath + "Scissors.BMP";
// break;
picBox.Image = ROCK_PAPER_SCISSORS_GAME_2.
Properties.Resources.Scissors;
break;
}
}
}
Solution
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 xyz
{
public partial class Form1 : Form
{
public Form1()
{
6. InitializeComponent();
}
// Module/method for when player selects rock.
private void rockPictureBox_Click(object sender, EventArgs e)
{
// Declare an integer variable.
int num1;
// Create a Random Object
Random rand = new Random();
// Get the random integer and assign it to num1.
num1 = rand.Next(3) + 1;
// Declare and display each players' moves and the winner.
switch (num1)
{
case 1:
computerTextLabel.Text = "Computer chooses rock";
playerTextLabel.Text = "You have choosen rock.";
winnerTextLabel.Text = "The computer and you have choosen rock. Therefore it is a tie.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = true;
computerPictureBox3.Visible = false;
computerPictureBox4.Visible = false;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = true;
playerPictureBox3.Visible = false;
playerPictureBox4.Visible = false;
break;
case 2:
computerTextLabel.Text = "Computer chooses paper";
playerTextLabel.Text = "You have choosen rock.";
winnerTextLabel.Text = "Paper can smoother a rock. Therefore the computer has won.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = false;
computerPictureBox3.Visible = true;
computerPictureBox4.Visible = false;
7. playerPictureBox1.Visible = false;
playerPictureBox2.Visible = true;
playerPictureBox3.Visible = false;
playerPictureBox4.Visible = false;
break;
case 3:
computerTextLabel.Text = "Computer Chooses scissors";
playerTextLabel.Text = "You have choosen rock.";
winnerTextLabel.Text = "A rock can crush scissors. Therefore, you have won.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = false;
computerPictureBox3.Visible = false;
computerPictureBox4.Visible = true;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = true;
playerPictureBox3.Visible = false;
playerPictureBox4.Visible = false;
break;
}
}
//Module/method for when player selects papaer.
private void paperPictureBox_Click(object sender, EventArgs e)
{
// Declare an integer variable.
int num1;
// Create a Random Object
Random rand = new Random();
// Get the random integer and assign it to num1.
num1 = rand.Next(3) + 1;
// Declare and display each players' moves and the winner.
switch (num1)
{
case 1:
computerTextLabel.Text = "Computer chooses rock.";
playerTextLabel.Text = "You have choosen paper.";
winnerTextLabel.Text = "Paper can smoother a rock. Therefore you have won.";
8. computerPictureBox1.Visible = false;
computerPictureBox2.Visible = true;
computerPictureBox3.Visible = false;
computerPictureBox4.Visible = false;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = false;
playerPictureBox3.Visible = true;
playerPictureBox4.Visible = false;
break;
case 2:
computerTextLabel.Text = "Computer chooses paper.";
playerTextLabel.Text = "You have choosen paper.";
winnerTextLabel.Text = "The computer and you have choosen paper. Therefore, it is a tie.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = false;
computerPictureBox3.Visible = true;
computerPictureBox4.Visible = false;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = false;
playerPictureBox3.Visible = true;
playerPictureBox4.Visible = false;
break;
case 3:
computerTextLabel.Text = "Computer Chooses scissors.";
playerTextLabel.Text = "You have choosen paper.";
winnerTextLabel.Text = "Scissors can cut paper. Therefore, the computer has won.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = false;
computerPictureBox3.Visible = false;
computerPictureBox4.Visible = true;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = false;
playerPictureBox3.Visible = true;
playerPictureBox4.Visible = false;
break;
}
9. }
//Module/Method for when player selects scissors.
private void scissorsPictureBox_Click(object sender, EventArgs e)
{
// Declare an integer variable.
int num1;
// Create a Random Object
Random rand = new Random();
// Get the random integer and assign it to num1.
num1 = rand.Next(3) + 1;
// Declare and display each players' moves and the winner.
switch (num1)
{
case 1:
computerTextLabel.Text = "Computer chooses rock.";
playerTextLabel.Text = "You have choosen scissors.";
winnerTextLabel.Text = "A rock can crush scissors. Therefore, the computer has won.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = true;
computerPictureBox3.Visible = false;
computerPictureBox4.Visible = false;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = false;
playerPictureBox3.Visible = false;
playerPictureBox4.Visible = true;
break;
case 2:
computerTextLabel.Text = "Computer chooses paper.";
playerTextLabel.Text = "You have choosen scissors.";
winnerTextLabel.Text = "Scissors can cut paper. Therefore, you have won.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = false;
computerPictureBox3.Visible = true;
computerPictureBox4.Visible = false;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = false;
10. playerPictureBox3.Visible = false;
playerPictureBox4.Visible = true;
break;
case 3:
computerTextLabel.Text = "Computer Chooses scissors.";
playerTextLabel.Text = "You have choosen scissors.";
winnerTextLabel.Text = "The computer and you have choosen scissors. Therefore, it is a tie.";
computerPictureBox1.Visible = false;
computerPictureBox2.Visible = false;
computerPictureBox3.Visible = false;
computerPictureBox4.Visible = true;
playerPictureBox1.Visible = false;
playerPictureBox2.Visible = false;
playerPictureBox3.Visible = false;
playerPictureBox4.Visible = true;
break;
}
}
private void exitButton_Click(object sender, EventArgs e)
{
// Close the form.
this.Close();
}
}
}
---------------------------------------------form1 design
namespace xyz
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
11. ///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.choosePictureBox = new System.Windows.Forms.PictureBox();
this.scissorsPictureBox = new System.Windows.Forms.PictureBox();
this.paperPictureBox = new System.Windows.Forms.PictureBox();
this.rockPictureBox = new System.Windows.Forms.PictureBox();
this.computerPictureBox4 = new System.Windows.Forms.PictureBox();
this.computerPictureBox3 = new System.Windows.Forms.PictureBox();
this.computerPictureBox2 = new System.Windows.Forms.PictureBox();
this.computerPictureBox1 = new System.Windows.Forms.PictureBox();
this.playerPictureBox4 = new System.Windows.Forms.PictureBox();
this.playerPictureBox3 = new System.Windows.Forms.PictureBox();
this.playerPictureBox2 = new System.Windows.Forms.PictureBox();
this.playerPictureBox1 = new System.Windows.Forms.PictureBox();
this.exitButton = new System.Windows.Forms.Button();
this.introTextLabel = new System.Windows.Forms.Label();
this.computerTextLabel = new System.Windows.Forms.Label();
this.playerTextLabel = new System.Windows.Forms.Label();
this.winnerTextLabel = new System.Windows.Forms.Label();
19. private System.Windows.Forms.Button exitButton;
private System.Windows.Forms.Label introTextLabel;
private System.Windows.Forms.Label computerTextLabel;
private System.Windows.Forms.Label playerTextLabel;
private System.Windows.Forms.Label winnerTextLabel;
}
}
--------------------------------------program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace xyz
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}