I am making a game of monopoly in c# and i have a dice roll but when i try to change one picturebox's colour on the board which represents a square where the player can be it will not change or display a string telling the user they have landed on a community chest for example. Like in the image i have provided player 1 is currently at position 17 which is the community chest, the picture box on that square should turn blue and there should be an announcement where the 6 is displayed telling the user to click the community chest button.
private void button2_Click(object sender, EventArgs e)
{
if (((P1Pos == 2) || (P2Pos == 2) || (P3Pos == 2) || (P4Pos == 2)) && ((P1Pos == 17) || (P2Pos == 17) || (P3Pos == 17) || (P4Pos == 17)) && ((P1Pos == 33) || (P2Pos == 33) || (P3Pos == 33) || (P4Pos == 33)))
{
label13.Text = "You have landed on a community chest. Please click the chest button.".ToString();
}
Random rnd = new System.Random();
int Dice = rnd.Next(1, 12);
label14.Text = Dice.ToString(); //Rolling the dice
if (CurrentPlayer == "Player 1")
{
label15.Text = (int.Parse(label15.Text) + Dice).ToString(); // Adding the roll number to the current piece position
P1Pos = int.Parse(label15.Text);
if (P1Pos > 40)
{
P1Pos = P1Pos - 40;
label15.Text = P1Pos.ToString(); // Checking if the piece is at 40 and taking 40 away as it is the biggest square number
}
CurrentPlayer = "Player 2";
NextPlayer = "Player 3";
return;
}
if (CurrentPlayer == "Player 2")
{
label22.Text = (int.Parse(label22.Text) + int.Parse(label14.Text)).ToString();
P2Pos = int.Parse(label22.Text);
if (P2Pos > 40)
{
P2Pos = P2Pos - 40;
label22.Text = P2Pos.ToString(); // Checking if the piece is at 40 and taking 40 away as it is the biggest square number
}
CurrentPlayer = "Player 3";
NextPlayer = "Player 4";
return;
}
if (CurrentPlayer == "Player 3")
{
label16.Text = (int.Parse(label16.Text) + int.Parse(label14.Text)).ToString();
P3Pos = int.Parse(label16.Text);
if (P3Pos > 40)
{
P3Pos = P3Pos - 40;
label16.Text = P2Pos.ToString(); // Checking if the piece is at 40 and taking 40 away as it is the biggest square number
}
CurrentPlayer = "Player 4";
NextPlayer = "Player 1";
return;
}
if (CurrentPlayer == "Player 4")
{
label21.Text = (int.Parse(label21.Text) + int.Parse(label14.Text)).ToString();
P4Pos = int.Parse(label21.Text);
if (P4Pos > 40)
{
P4Pos = P4Pos - 40;
label21.Text = P4Pos.ToString(); // Checking if the piece is at 40 and taking 40 away as it is the biggest square number
}
CurrentPlayer = "Player 1";
NextPlayer = "Player 2";
return;
}
if (((P1Pos == 2) || (P2Pos == 2) || (P3Pos == 2) || (P4Pos == 2)) && ((P1Pos == 17) || (P2Pos == 17) || (P3Pos == 17) || (P4Pos == 17)) && ((P1Pos == 33) || (P2Pos == 33) || (P3Pos == 33) || (P4Pos == 33)))
{
label14.Text = "You have landed on a community chest. Please click the chest button.";
}
if ((P1Pos == 17) || (P2Pos == 17) || (P3Pos == 17) || (P4Pos == 17))
{
label14.Text = "You have landed on a community chest. Please click the chest button.";
}
if ((P1Pos == 33) || (P2Pos == 33) || (P3Pos == 33) || (P4Pos == 33))
{
label14.Text = "You have landed on a community chest. Please click the chest button.";
}
}

Aucun commentaire:
Enregistrer un commentaire