I have been working on a dice game which allows for two players to play.
Here are my game rules:
- Player rolls 5 dice and the values are added to their totalScore;
- Rolling a 1 or 4 will result in those dice being removed and nothing is added to their totalScore.
- Player continues to roll their remaining dice until they have no dice remaining.
- Players turn ends when they have no dice remaining and they receive their totalScore
My question is, how can I obtain a Player's totalScore to output on a label once their turn is completed?
Please note, I have just started to program, so I am very new. I appreciate the feedback.
Here is my code so far,
public partial class Form1 : Form
{
Image[] diceImages;
Label[] labels;
int[] dice;
int diceTotal;
bool rolledOneOrFour;
Random r;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
diceImages = new Image[]
{
Properties.Resources.blank,
Properties.Resources.one,
Properties.Resources.two,
Properties.Resources.three,
Properties.Resources.four,
Properties.Resources.five,
Properties.Resources.six
};
dice = new int[5];
r = new Random();
diceTotal = 0;
labels = new Label[]
{
lbl_dice1,
lbl_dice2,
lbl_dice3,
lbl_dice4,
lbl_dice5
};
}
public void btn_roll_Click(object sender, EventArgs e)
{
rollDice();
}
private void rollDice()
{
bool OneOrFourRolled = false;
int rollTotal = 0;
int sum = 0;
int playerScore = 0;
for (int i = 0; i < dice.Length; i++)
{
if (rolledOneOrFour)
{
if (dice[i] == 1 || dice[i] == 4)
{
dice[i] = 0;
}
if (dice[i] == 0)
{
continue;
}
}
int rollDice = r.Next(1, 7);
dice[i] = rollDice;
sum += rollDice;
if (dice[roll] == 1 || dice[roll] == 4)
{
TwoOrFiveRolled = true;
}
rollTotal += dice[roll];
}
if (!TwoOrFiveRolled)
{
diceTotal += rollTotal;
lb_liveResults.Items.Add("You scored " + sum + " points for this roll");
}
penalty = true;
for (int i = 0; i < labels.Length; i++)
{
labels[i].Image = diceImages[dice[i]];
}
}