こんにちは私は1から100int配列にchar( 'X')を入れる方法は?チックタックつま先のようなもの - - しかし、私は大きな配列を使用
に、たとえばそれはゲームだ、私は数字を持っているint型の2次元配列型を持っています。だから、私は文字 'X'または 'O'をこの配列に配置する必要があります。しかし、問題は、int配列にこれらの文字を配置する方法がわからないことです。私はコンソールだけを使いたいと思う。
私はchar型の配列型を作成しようとしましたが、配列で数値を埋めることができません。
ユーザーが持っているならば、私はそれを行う方法を知っているが、私はそれを行うにはどのように何かアドバイスのために幸せになるいくつかの数字を入れてますが、それは良い見ていない...
たい。
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
でも数字を文字列に入れることはできますか? –