Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用复选框保存变量_C#_.net_Visual Studio_Checkbox - Fatal编程技术网

C# 如何使用复选框保存变量

C# 如何使用复选框保存变量,c#,.net,visual-studio,checkbox,C#,.net,Visual Studio,Checkbox,我目前正在做一个项目,我们将编写一个yahtzee游戏。游戏需要掷5个骰子(使用随机选择5个不同的骰子面图像),玩家需要能够持有骰子,以便在第二次和第三次掷骰子时,如果选中相关复选框,骰子保持不变。我希望使用if语句来实现这一点。如何将其合并到代码中 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using

我目前正在做一个项目,我们将编写一个yahtzee游戏。游戏需要掷5个骰子(使用随机选择5个不同的骰子面图像),玩家需要能够持有骰子,以便在第二次和第三次掷骰子时,如果选中相关复选框,骰子保持不变。我希望使用if语句来实现这一点。如何将其合并到代码中

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace dice2
{
public partial class Form1 : Form
{
    Image[] DiceImages; // Image array
    int[] dice; //intiger array
    Random rand;
    CheckBox[] boxes = new CheckBox[4];


    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        DiceImages = new Image[]
       {
          Properties.Resources.dice_blank,
          Properties.Resources.dice_1,
          Properties.Resources.dice_2,
          Properties.Resources.dice_3,
          Properties.Resources.dice_4,
          Properties.Resources.dice_5,
          Properties.Resources.dice_6
 };

        dice = new int[5]; //dice length

        rand = new Random();
    }

    private void btn1_Click(object sender, EventArgs e)
    {
        RollDice();
    }

    private void RollDice()
    {
        for (int i = 0; i < dice.Length; i++)  //start at 0, i is equal to less than the dice length (5) 
            dice[i] = rand.Next(1, 7);//dice is edice[int] = rand.Next(1, 7);

        lbl1.Image = DiceImages[dice[0]];
        lbl2.Image = DiceImages[dice[1]];
        lbl3.Image = DiceImages[dice[2]];
        lbl4.Image = DiceImages[dice[3]];
        lbl5.Image = DiceImages[dice[4]];




    }


    private void cb1_CheckedChanged (object sender, EventArgs e)
    {

    }



    private void cb2_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void cb3_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void cb4_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void cb5_CheckedChanged(object sender, EventArgs e)
    {

    }


    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间2
{
公共部分类Form1:Form
{
Image[]DiceImages;//图像数组
int[]骰子;//intiger数组
随机兰德;
复选框[]框=新复选框[4];
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
DiceImages=新图像[]
{
Properties.Resources.dice_blank,
Properties.Resources.dice_1,
Properties.Resources.dice_2,
Properties.Resources.dice_3,
Properties.Resources.dice_4,
Properties.Resources.dice_5,
Properties.Resources.dice_6
};
骰子=新整数[5];//骰子长度
rand=新随机数();
}
私有无效btn1_单击(对象发送方,事件参数e)
{
滚动骰子();
}
私有void RollDice()
{
对于(int i=0;i
在获取新号码之前,请检查复选框是否如下所示:

private void RollDice()
{
    for (int i = 0; i < dice.Length; i++)
      if(!boxes[i].Checked)
        dice[i] = rand.Next(1, 7);
private void RollDice()
{
for(int i=0;i