public class MatrixCardManager
{
public static int[,] ReadMatrixCardFromString(string matrixStr)
{
int[,] arr1 = new int[5, 5];
int[] tempArr = new int[25];
int k = 0;
string[] tempArrStr = matrixStr.Split(',');
for (int i = 0; i < tempArr.Length; i++)
{
tempArr[i] = Convert.ToInt32(tempArrStr[i]);
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
arr1[i, j] = tempArr[k];
k++;
}
}
return arr1;
}
public static string SaveMatrixIntoString(int[,] arr)
{
string matrixStr = String.Empty;
int[] lineArr = new int[25];
int k = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
lineArr[k] = arr[i, j];
k++;
}
}
for (int i = 0; i < lineArr.Length; i++)
{
matrixStr += lineArr[i];
if (i < 24)
{
matrixStr += ",";
}
}
return matrixStr;
}
public static void PrintMatrix(int[,] arr)
{
Console.WriteLine(" | A/tB/tC/tD/tE");
Console.WriteLine("-------------------------------------------");
for (int k = 0; k < 5; k++)
{
Console.Write(k + " | ");
for (int l = 0; l < 5; l++)
{
Console.Write(arr[k, l] + "/t");
}
Console.WriteLine();
}
}
public static int[,] GenerateRandomMatrix()
{
Random r = new Random();
int[,] arr = new int[5, 5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
arr[i, j] = r.Next(0, 100);
}
}
return arr;
}
public static char GetColCode(int colIndex)
{
char colCode = '-';
switch (colIndex)
{
case 0:
colCode = 'A';
break;
case 1:
colCode = 'B';
break;
case 2:
colCode = 'C';
break;
case 3:
colCode = 'D';
break;
case 4:
colCode = 'E';
break;
default:
break;
}
return colCode;
}
public static bool Validate(int[,] arr, int colIndex1, int rowIndex1, int colIndex2, int rowIndex2, int colIndex3, int rowIndex3, string userInput, bool validFlag)
{
try
{
string[] inputArr = userInput.Split(',');
bool OK0 = arr[rowIndex1, colIndex1] == Convert.ToInt32(inputArr[0]);
bool OK1 = arr[rowIndex2, colIndex2] == Convert.ToInt32(inputArr[1]);
bool OK2 = arr[rowIndex3, colIndex3] == Convert.ToInt32(inputArr[2]);
if (OK0 && OK1 && OK2)
{
validFlag = true;
}
else
{
validFlag = false;
}
}
catch (Exception)
{
Console.WriteLine("Oh, **!");
}
return validFlag;
}
}