Skip to content

Instantly share code, notes, and snippets.

@Deanout
Created October 16, 2017 15:49
Show Gist options
  • Save Deanout/0a212c5c08a619198ecca5add47ee694 to your computer and use it in GitHub Desktop.
Save Deanout/0a212c5c08a619198ecca5add47ee694 to your computer and use it in GitHub Desktop.
public partial class Form1 : Form {
public static Random r = new Random();
private int score = 0;
private int die1;
private int die2;
private int dieTotal;
private int point;
public Form1() {
InitializeComponent();
}
private void textBox1_TextChanged(object sender) {
}
private void lblPoint_Click(object sender) {
}
private void btnRoll_Click(object sender) {
die1 = 0;
die2 = 0;
dieTotal = 0;
point = 0;
die1 = r.Next(1, 7);
die2 = r.Next(1, 7);
dieTotal = die1 + die2;
txtDie1.Text = die1.ToString();
txtDie2.Text = die2.ToString();
txtTotal.Text = dieTotal.ToString();
// Call the show dice method and pass in the two die rolls.
showDice(die1, die2);
// Switch case that handles the actual game logic.
switch(dieTotal) {
case 2:
case 3:
case 12:
// Shooter loses!
break;
case 7:
case 11:
// Shooter wins!
break;
case 4:
case 5:
case 6:
case 8:
case 9:
case 10:
// Update Points
break;
default:
break;
}
point = total;
txtPoint.Text = point.ToString();
}
private void showDice(int firstDie, int secondDie) {
switch(firstDie) {
case 1:
picDieOne1.Visible = true;
break;
case 2:
picDieOne2.Visible = true;
break;
case 3:
picDieOne3.Visible = true;
break;
case 4:
picDieOne4.Visible = true;
break;
case 5:
picDieOne5.Visible = true;
break;
case 6:
picDieOne6.Visible = true;
break;
default:
break;
}
switch(secondDie) {
case 1:
picDieTwo1.Visible = true;
break;
case 2:
picDieTwo2.Visible = true;
break;
case 3:
picDieTwo3.Visible = true;
break;
case 4:
picDieTwo4.Visible = true;
break;
case 5:
picDieTwo5.Visible = true;
break;
case 6:
picDieTwo6.Visible = true;
break;
default:
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment