嗨我有二维数组类型的int我有数字,例如从1到100.如何将char('X')设置为int数组?
这是一个游戏 - 类似Tic-Tac-Toe - 但我使用更大的数组。所以我需要把用户的字符'X'或'O'放到这个数组中。但问题是我不能(不知道)如何把这些字符放在那个int数组中。我只想使用控制台。
我试过让数组类型的字符,但然后我不能用数字填充数组。
我知道该怎么做,如果用户将有希望把一些数字,但然后,它看起来并不好......
我会很高兴的任何建议如何做到这一点。
public void Napln() { //filling the array
int poc = 1;
for (int i = 0; i < pole.GetLength(1); i++)
{
Console.Write(" ");
for (int j = 0; j < pole.GetLength(0); j++)
{
if (poc < 10)
Console.Write(" " + (pole[j, i] = poc++) + " | ");
else if (poc < 100)
Console.Write((pole[j,i] = poC++) + " | ");
else
Console.Write((pole[j, i] = poc++) + " | ");
}
Console.WriteLine();
for (int v = 0; v < roz1; v ++)
Console.Write("_____|");
Console.WriteLine();
}
Console.WriteLine();
public void Pozice (int vyber) //find the user choice
{
for (int i = 0; i < pole.GetLength(1); i ++)
{
for (int j = 0; j < pole.GetLength(0); j ++)
{
if (pole[i, j] == vyber)
{
pole[i, j] = 'X';
hraci.Vypis();
}
}
}
}
public void Vypis() //print the same with change of user choice
{
for (int i = 0; i < pole.GetLength(1); i ++)
{
Console.Write(" ");
for (int j = 0; j < pole.GetLength(0); j ++)
{
if (pole[j,i] < 10)
Console.Write(" " + pole[j, i] + " | ");
else if (pole[j,i] < 100)
Console.Write(pole[j, i] + " | ");
else
Console.Write(pole[j, i] + " | ");
}
Console.WriteLine();
for (int v = 0; v < roz1; v++)
Console.Write("_____|");
Console.WriteLine();
}
}
我是C#中的新人,尤其是OOP。所以如果你有更多的建议,我会很高兴。
***显示代码*** – abelenky
为什么你需要填写数字板? – Lee
但你可以把数字放在字符中? –