I'm having trouble with the or operator and random number generator. I'm wanting the random number generator to pull a number between 1 and h with h been chosen by a user and stored as 1,6,11 and 16 then I wish the if statement to look at the random number and decide if it is to do what I have programmed or go and perform the else statement. At the moment it only seems to perform the if statement and never the else (the second else, the first one works fine). The code I have is
Random random = new Random();
int ran = random.Next(1, h);
if (s1 == 0 & s2 == 0 & s3 == 1)
{
s3 = s3 - 1;
cover0.Visible = true;
p1slable.Visible = true;
p2slable.Visible = true;
playagain.Visible = true;
score.Visible = true;
p1score.Visible = true;
p2score.Visible = true;
c = c + 1;
p2slable.Text = "" + c.ToString();
labelscore2.Visible = true;
winner2.Visible = true;
hintcover.Visible = true;
e1.Visible = false;
e2.Visible = false;
e3.Visible = false;
}
else
{
if (s1 == 0 & s2 == 0 & s3 == 2)
{
if (ran == 1 || ran == 3 || ran == 4 || ran == 5 || ran == 9 || ran == 10 || ran == 15)
{
s3 = s3 - 2;
cover0.Visible = true;
p1slable.Visible = true;
p2slable.Visible = true;
playagain.Visible = true;
score.Visible = true;
p1score.Visible = true;
p2score.Visible = true;
c = c + 1;
p2slable.Text = "" + c.ToString();
labelscore2.Visible = true;
winner2.Visible = true;
hintcover.Visible = true;
e1.Visible = false;
e2.Visible = false;
e3.Visible = false;
}
else { s3 = s3 - 1; }
and i am using c# 2015
Aucun commentaire:
Enregistrer un commentaire