/// <summary> /// метод инициализации игры /// </summary> public void Run() { BaseBoard = new PieceChar[Console.WindowHeight, Console.WindowWidth]; PreStateBoard = new PieceChar[Console.WindowHeight, Console.WindowWidth]; Ground = new PieceChar[Console.WindowHeight, Console.WindowWidth]; Wall = new PieceChar[Console.WindowHeight, Console.WindowWidth]; Snake = new PieceChar[10]; //тестовый игрок player = new PieceChar[1]; player[0] = new PieceChar(10, 10, ConsoleColor.Yellow, '█'); for (int i = 0; i < Console.WindowHeight; i++) { for (int j = 0; j < Console.WindowWidth; j++) { BaseBoard[i, j] = new PieceChar(i, j, ConsoleColor.White, ' '); PreStateBoard[i, j] = new PieceChar(i, j, ConsoleColor.White, ' '); Ground[i, j] = new PieceChar(i, j, ConsoleColor.White, ' '); Wall[i, j] = new PieceChar(i, j, ConsoleColor.White, ' '); } } ReadFiles(ref Wall, "Wall.txt"); Console.Clear(); }
/// <summary> /// чтение карты из файла /// </summary> /// <param name="obj">массив</param> /// <param name="name">имя файла</param> void ReadFiles(ref PieceChar[,] obj, string name) { string[] words = File.ReadAllLines(name); for (int i = 0; i < obj.GetLength(0); i++) { for (int j = 0; j < obj.GetLength(1); j++) { if (words[i][j] != '.') obj[i, j].Body = words[i][j]; } } }
/// <summary> /// копирование массива в базовый /// </summary> /// <param name="obj"></param> void CopyArray2Base(PieceChar[] obj) { for (int i = 0; i < obj.Length; i++) { BaseBoard[obj[i].Y, obj[i].X].Body = obj[i].Body; BaseBoard[obj[i].Y, obj[i].X].Color = obj[i].Color; } }
/// <summary> /// копирование 2D массива в базовый /// </summary> void CopyArray2Base(PieceChar[,] obj) { for (int i = 0; i < obj.GetLength(0); i++) { for (int j = 0; j < obj.GetLength(1); j++) { BaseBoard[obj[i, j].Y, obj[i, j].X].Body = obj[i, j].Body; BaseBoard[obj[i, j].Y, obj[i, j].X].Color = obj[i, j].Color; } } }
/// <summary> /// очистка всего массива ' ' /// </summary> /// <param name="obj">массив</param> void ClearArray(ref PieceChar[,] obj) { for (int i = 0; i < Console.WindowHeight; i++) { for (int j = 0; j < Console.WindowWidth; j++) { obj[i, j].Body = ' '; obj[i, j].Color = ConsoleColor.White; } } }