皆さん、私はプロジェクト、try catchブロックに問題があります。真スキップホールドチェックとは、すべてのサイコロを転がした場合ダイスローリングで問題をキャッチしようとしました。チェックボックスの問題
falseの場合、以下の(「ロック」何とか、新たに開催されたサイコロを(試してみてください、第1ロールのための
まずチェック)AND:私は、次の操作を行うためにそれを必要としますロールunheldサイコロ)
何のサイコロが開催されていない場合は、例外
を投げる私は私のコードを添付しています。
Random = random.Next(0, 6);
diceImages[i].Image = dieImages[Random];
dieImages
が本当にdiceImages
あるべきと仮定すると、(そうでない場合はコンパイルされません) 使用している:ので、このコードには多くの問題があります誰かが
public partial class FrmBupkis1 : Form
{
private PictureBox[] diceImages;
private CheckBox[] holds;
private Random rnd = new Random();
public Frm1()
{
InitializeComponent();
diceImages = new PictureBox[6];
diceImages[0] = pbxDie0;
diceImages[1] = pbxDie1;
diceImages[2] = pbxDie2;
diceImages[3] = pbxDie3;
diceImages[4] = pbxDie4;
diceImages[5] = pbxDie5;
holds = new CheckBox[6];
holds[0] = chbHold0;
holds[1] = chbHold1;
holds[2] = chbHold2;
holds[3] = chbHold3;
holds[4] = chbHold4;
holds[5] = chbHold5;
}
private void rollBtn_Click(object sender, EventArgs e)
{
//First Check for first roll, if true skip hold checks and roll all dice
//If false, Try the following ('lock' newly held dice (somehow) AND roll unheld dice)
//If no dice are held, throw exception
for (int i = 0; i < 6; i++)
{
//if die is not held, then assign random number to image box
if (holds[i].Checked == false)
diceImages[i].Image = iglDice.Images[rnd.Next(6)];
try
{
Random = random.Next(0, 6);
diceImages[i].Image = dieImages[Random];
rollBtn = true;
}
catch (FormatException ex)
{
Console.WriteLine(ex.Message, "Error. Try Again.");
}
}
}
private void gameOverBtn_Click(object sender, EventArgs e)
{
for (int i = 0; i < 6; i++)
{
diceImages[i].Image = null;
holds[i].Checked = false;
holds[i].Enabled = true;
}
}
private void quitBtn_Click(object sender, EventArgs e)
{
//btnQuit
this.Close();
}
}
なぜ各ダイを2回「リロール」していますか? –