預期:字符'H'在由默認'X'構成的5x5數組中移動。在C#中的數組中移動一個字符
結果1:通過添加'H'和'P'而不是替換匹配的索引'X'來擴展網格。
結果2:char'H'不動。
這裏是到目前爲止的代碼:
class Mainclass
{
public static void Main(string[] args)
{
Console.WriteLine("The Board Game");
Console.WriteLine();
Console.WriteLine(">>Press any key to begin<<");
Console.ReadKey();
Console.Clear();
Console.WriteLine("The Board Game");
Console.WriteLine();
CreateGrid();
Console.WriteLine();
Console.WriteLine("H = your hero");
Console.WriteLine();
Console.WriteLine("X = floor tiles");
Console.WriteLine();
Console.WriteLine("P = enemy pawn");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press the arrows in your keyboard to move in that direction");
}
public static void CreateGrid()
{
int width = 5;
int height = 5;
char[,] grid = new int[width, height];
grid[2, 2] = 'H';
grid[4, 4] = 'P';
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Console.Write(grid[x, y] + " ");
}
Console.WriteLine();
}
if (ConsoleKeydown(ConsoleKey.up)){
get hero.index[,];
newHeroPosition = Hero.index +1, +0;
char hero.index = H;
char newHeroPosition = x;
}
/*I want the tile to be identified and swap the char value
of it with the one above it on the grid */
}
}
}
「我需要XYZ」 ......這不是一個代碼服務站點......但一個地方來形容你是不是嘗試管理和閱讀,並具有特定的問題後做了什麼。 ...至於在你的數組中有字母......使用'char [,]'而不是 –
@Nuno本網站不需要Salutations。我可能會在警方降臨之前將他們移走。 –
Hi @GiladGreen!對不起,如果我在這裏錯過了元。感謝關於char變量類型的提示。您可能會發現對我的目標有用的任何參考也非常受歡迎。 –