mardi 23 février 2016

How to hold a variable using a checkbox

i am currently working on a project where we are to code a game of yahtzee. The game requires 5 dice to be rolled ( using random to select 5 different dice face images) and players need the ability to hold die so that on the second and third rolls if the correlated check box is checked , the die stays the same. I wish to do this using if statements. How do i incorporate this into my code?

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)
    {

    }


    }
}




Aucun commentaire:

Enregistrer un commentaire