Reputation: 127
The user will play a matching game. If the item matches the number, it'll say it matched otherwise, it won't match. All of the matched number are passed on the matchedNum array. The initial value of the matchedNum array is zeroes. How do i stop the loop when there's no more zeroes in the array?
class Program
{
public static int[,] memoryNum = { { 2, 1, 7, 3 }, { 5, 4, 9, 6 }, { 3, 7, 2, 4 }, { 6, 5, 1, 9 } };
public static int[,] matchedNum = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
public static int row1 = 0;
public static int col1 = 0;
public static int row2 = 0;
public static int col2 = 0;
public Boolean matches = true;
public static int tries = 3;
static void Main(string[] args)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
Console.Write("* ");
if (j == 3)
{
Console.WriteLine("");
}
}
}
while (tries != 0)
{
Console.Write("\nEnter row(First Num): ");
row1 = Convert.ToInt32(Console.ReadLine());
checker(row1);
Console.Write("Enter col(First Num): ");
col1 = Convert.ToInt32(Console.ReadLine());
checker(col1);
Console.Write("Enter row(Second Num): ");
row2 = Convert.ToInt32(Console.ReadLine());
checker(row2);
Console.Write("Enter col(Second Num): ");
col2 = Convert.ToInt32(Console.ReadLine());
checker(col2);
if (memoryNum[row1 - 1, col1 - 1] == memoryNum[row2 - 1, col2 - 1])
{
matchedNum[row1 - 1, col1 - 1] = memoryNum[row1 - 1, col1 - 1];
matchedNum[row2 - 1, col2 - 1] = memoryNum[row2 - 1, col2 - 1];
displayMatched(matchedNum);
Console.WriteLine("Matched!");
}
else
{
displayNotMatched(memoryNum);
tries--;
Console.WriteLine("Did not match, Please try again!");
}
//if there's no zero in the array, break;
}
if(tries == 0)
Console.WriteLine("Number of tries exceeded! Play Again?");
Console.ReadKey();
}
}
Upvotes: 0
Views: 88