I can't seem to get my field / list working. I want to add to the list and use the list in CheckUserInput
and PlayerMove
methods. It says it's not being used but I am using it in those methods without any errors.
I tried to play around with it for a bit and all the methods are static methods so I had to make a static field.
private static List<string> AlreadyUsed = new List<string>();
private static void CheckUserInput(ref int player, ref string answer, ref bool error)
{
AlreadyUsed.Add("");
if(int.Parse(answer) > 9)
{
Console.WriteLine("You have entered a value outside the array. Skipping your turn.");
error = true;
}
else
{
for (int i = 0; i <= 9; i++)
{
if (AlreadyUsed[i] == "X" || AlreadyUsed[i] == "O")
{
Console.WriteLine("You have already entered a value in this slot. Skipping your turn.");
error = true;
}
}
}
}
private static void PlayerMove(ref string answer, string[] arr, ref int player) //make whole new class for this method?
{
for (int i = 0; i <= 8; i++) //make player move
{
if (answer == arr[i])
{
if (player == 1)
{
arr[i] = "X";
AlreadyUsed.Add(answer);
}
else
{
arr[i] = "O";
AlreadyUsed.Add(answer);
}
}
}
}
I used CheckUserInput
before PlayerMove
hence adding the extra value in the list. I was met with a runtime error.
Thank you!