Exemple #1
0
        /// <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();
        }
Exemple #2
0
        /// <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();
        }
Exemple #3
0
        /// <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];
                }
            }
        }
Exemple #4
0
 /// <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;
     }
 }
Exemple #5
0
 /// <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;
         }
     }
 }
Exemple #6
0
 /// <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;
         }
     }
 }