Hi, I am new here and was looking for a little help. I am writing a console application to play yahtzee. I have a die class, a dice class (with a dice array composed of five die), and my yahtzee class that has my Main method. My die has a private bool variable held. I created a get and set for held. I created a switch to allow the user to hold certian die:
public class Die
{
private int count; //value of die
private bool held; //false if not held, true if held
public Die()
{
count = 0; //pre-roll
held = false; //dice is not being held to start
}
public int Count
{
get
{
return count; //gives the value of the die
}
}
public bool Held
//assign whether the dice is held or not
{
get
{
return held;
}
set
{
held = value;
}
}
...
public void UserInputAfterRoll(Dice dice, Yahtzee yahtzee, ScoreSheet scoreSheet01)
{
Console.Write("What would you like to do?");
string userChoice = Console.ReadLine();
switch (userChoice)
{
case "Hold Die #1":
dice.Dice01[0].Held = true;
Console.WriteLine("Dice #1 has been held.");
goto NextChoice;
The problem is that the held variable is not changing to true. I set a breakpoint on the code and a watch on held. Before my code reached the set for Held it said identifer 'held' out of scope, then it seems to set held to true, but then it says identifier held is out of scope again. Can anyone offer suggestions as to why the dice are not holding. Is it because of the out of scope error? or something else? Sorry if I did not provide enough details of my code. If you would like to see all of the code just let me know.
PS. The only other thing I can think of is after case "Hold Die #1" i have a goto statement that returns to the switch so the user can hold another die, would this screw with it at all?