私のコードの一部には、変数の1つである唯一の違いであるifステートメントが何度も何度も繰り返されるセクションがあります。コードを構造化するより良い方法はありますか?
if (buttonArray[m, j].BackColor == levelTwo && buttonArray[m, a].BackColor == levelTwo
&& buttonArray[i, j].BackColor == levelTwo)
{
buttonArray[i, j].BackColor = levelThree;
buttonArray[m, j].BackColor = Color.Transparent;
buttonArray[m, a].BackColor = Color.Transparent;
}
if (buttonArray[m, j].BackColor == levelThree && buttonArray[m, a].BackColor == levelThree
&& buttonArray[i, j].BackColor == levelThree)
{
buttonArray[i, j].BackColor = levelFour;
buttonArray[m, j].BackColor = Color.Transparent;
buttonArray[m, a].BackColor = Color.Transparent;
}
if (buttonArray[m, j].BackColor == levelFour && buttonArray[m, a].BackColor == levelFour
&& buttonArray[i, j].BackColor == levelFour)
{
buttonArray[i, j].BackColor = levelFive;
buttonArray[m, j].BackColor = Color.Transparent;
buttonArray[m, a].BackColor = Color.Transparent;
}
if (buttonArray[m, j].BackColor == levelFive && buttonArray[m, a].BackColor == levelFive
&& buttonArray[i, j].BackColor == levelFive)
{
buttonArray[i, j].BackColor = levelSix;
buttonArray[m, j].BackColor = Color.Transparent;
buttonArray[m, a].BackColor = Color.Transparent;
}
if (buttonArray[m, j].BackColor == levelSix && buttonArray[m, a].BackColor == levelSix
&& buttonArray[i, j].BackColor == levelSix)
{
buttonArray[i, j].BackColor = levelSeven;
buttonArray[m, j].BackColor = Color.Transparent;
buttonArray[m, a].BackColor = Color.Transparent;
}
if (buttonArray[m, j].BackColor == levelSeven && buttonArray[m, a].BackColor == levelSeven && buttonArray[i, j].BackColor == levelSeven)
{
buttonArray[i, j].BackColor = levelEight;
buttonArray[m, j].BackColor = Color.Transparent;
buttonArray[m, a].BackColor = Color.Transparent;
}