ASDV-C-Sharp/MP4/RPS_CalebFontenot/RCS_CalebFontenot/Form1.cs

221 lines
8.5 KiB
C#
Raw Normal View History

2022-11-16 17:48:22 -06:00
namespace RCS_CalebFontenot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int cpuAction;
2022-11-16 19:07:09 -06:00
private long cpuRockCount = 0, playerRockCount = 0, cpuScissorsCount = 0, playerScissorsCount = 0, cpuPaperCount = 0, playerPaperCount = 0;
private void updateTextBoxes()
{
// Increment the textboxes!
cpuRockCounter.Text = "Rock: " + cpuRockCount.ToString();
playerRockCounter.Text = "Rock: " + playerRockCount.ToString();
cpuPaperCounter.Text = "Paper: " + cpuPaperCount.ToString();
playerPaperCounter.Text = "Paper: " + playerPaperCount.ToString();
cpuScissorsCounter.Text = "Scissors: " + cpuScissorsCount.ToString();
playerScissorsCounter.Text = "Scissors: " + playerScissorsCount.ToString();
}
private void winIncrement(string whatToIncrement)
{
// Increment the variables!
switch (whatToIncrement)
{
case "rockDraw":
cpuRockCount++;
playerRockCount++;
break;
case "paperDraw":
cpuPaperCount++;
playerPaperCount++;
break;
case "scissorsDraw":
cpuScissorsCount++;
playerScissorsCount++;
break;
case "cpuRock":
cpuRockCount++;
break;
case "playerRock":
playerRockCount++;
break;
case "cpuPaper":
cpuPaperCount++;
break;
case "playerPaper":
playerPaperCount++;
break;
case "cpuScissors":
cpuScissorsCount++;
break;
case "playerScissors":
playerScissorsCount++;
break;
}
updateTextBoxes();
}
2022-11-16 17:48:22 -06:00
private void endGame()
{
// Disable the interactivity of the images.
rockPictureBox.Enabled = false;
paperPictureBox.Enabled = false;
scissorPictureBox.Enabled = false;
// Re-enable the newGameButton.
newGameButton.Enabled = true;
}
private void playRound(int action)
{
// The action variable determines what we will do.
switch (action)
{
case -1: //The Player is starting the game.
Random rng = new Random();
2022-11-16 19:07:09 -06:00
cpuAction = rng.Next(0, 3);
2022-11-16 17:48:22 -06:00
statusLabel.Text = "The computer has chosen a move. Please make yours.";
// Clear the computer choice image.
cpuMove.Visible = false;
break;
case 0: // The player has chosen rock.
switch (cpuAction)
{
case 0:
statusLabel.Text = "The computer has chosen rock. You chose rock as well. It is a draw.";
2022-11-16 19:07:09 -06:00
winIncrement("rockDraw");
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
2022-11-16 19:07:09 -06:00
cpuMove.Image = Properties.Resources.Rock;
2022-11-16 17:48:22 -06:00
break;
case 1:
statusLabel.Text = "The computer chose paper. You chose rock. The computer wins!";
2022-11-16 19:07:09 -06:00
winIncrement("cpuPaper");
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
2022-11-16 19:07:09 -06:00
cpuMove.Image = Properties.Resources.Paper;
2022-11-16 17:48:22 -06:00
break;
case 2:
statusLabel.Text = "The computer chose scissors. You chose rock. You win!";
2022-11-16 19:07:09 -06:00
winIncrement("playerScissors");
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
2022-11-16 19:07:09 -06:00
cpuMove.Image = Properties.Resources.Scissors;
2022-11-16 17:48:22 -06:00
break;
}
endGame();
break;
case 1:
switch (cpuAction)
{
case 0:
statusLabel.Text = "The computer has chosen rock. You chose paper. You win!";
2022-11-16 19:07:09 -06:00
winIncrement("cpuRock");
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
2022-11-16 19:07:09 -06:00
cpuMove.Image = Properties.Resources.Rock;
2022-11-16 17:48:22 -06:00
break;
case 1:
statusLabel.Text = "The computer chose paper. You chose paper as well. It is a draw.";
2022-11-16 19:07:09 -06:00
winIncrement("paperDraw");
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
2022-11-16 19:07:09 -06:00
cpuMove.Image = Properties.Resources.Paper;
2022-11-16 17:48:22 -06:00
break;
case 2:
statusLabel.Text = "The computer chose scissors. You chose paper. The computer wins!";
2022-11-16 19:07:09 -06:00
winIncrement("cpuScissors");
cpuMove.Image = Properties.Resources.Scissors;
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
break;
}
endGame();
break;
case 2:
{
switch (cpuAction)
{
case 0:
statusLabel.Text = "The computer has chosen rock. You chose scissors. The computer wins!";
2022-11-16 19:07:09 -06:00
winIncrement("cpuRock");
cpuMove.Image = Properties.Resources.Rock;
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
break;
case 1:
statusLabel.Text = "The computer chose paper. You chose scissors. You win!";
2022-11-16 19:07:09 -06:00
winIncrement("playerScissors");
cpuMove.Image = Properties.Resources.Paper;
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
break;
case 2:
2022-11-16 19:07:09 -06:00
statusLabel.Text = "The computer chose scissors. You chose scissors as well. It is a draw.";
winIncrement("paperDraw");
cpuMove.Image = Properties.Resources.Scissors;
2022-11-16 17:48:22 -06:00
cpuMove.Visible = true;
break;
}
}
endGame();
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Do some stuff on start
statusLabel.Text = "Ready. Press 'New Game' to start a game.";
// Disable the interactivity of the images.
rockPictureBox.Enabled = false;
paperPictureBox.Enabled = false;
scissorPictureBox.Enabled = false;
}
2022-11-16 19:07:09 -06:00
private void clearButton_Click(object sender, EventArgs e)
{
cpuRockCount = 0;
playerRockCount = 0;
cpuScissorsCount = 0;
playerScissorsCount = 0;
cpuPaperCount = 0;
playerPaperCount = 0;
updateTextBoxes();
}
2022-11-16 17:48:22 -06:00
private void newGameButton_Click(object sender, EventArgs e)
{
// Enable the images' interactivity.
rockPictureBox.Enabled = true;
paperPictureBox.Enabled = true;
scissorPictureBox.Enabled = true;
// Disable this button.
newGameButton.Enabled = false;
playRound(-1);
}
private void rockPictureBox_Click(object sender, EventArgs e)
{
playRound(0);
}
private void paperPictureBox_Click(object sender, EventArgs e)
{
playRound(1);
}
private void scissorPictureBox_Click(object sender, EventArgs e)
{
playRound(2);
}
2022-11-17 21:59:26 -06:00
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
2022-11-16 17:48:22 -06:00
}
2022-11-17 21:59:26 -06:00
}