Advertisement
Nickolya

Untitled

Mar 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.CursorVisible = false;
  14.             int[,] maze = new int[10, 10]
  15.             {
  16.                 {1,1,1,1,1,1,1,1,1,1},
  17.                 {1,0,1,0,0,0,0,0,0,1},
  18.                 {1,0,1,0,1,0,1,1,0,1},
  19.                 {1,0,1,0,1,0,1,1,0,1},
  20.                 {1,0,1,0,1,0,1,1,0,1},
  21.                 {1,0,1,0,1,0,1,1,2,1},
  22.                 {1,0,1,0,1,0,1,1,0,1},
  23.                 {1,0,1,0,1,0,0,1,0,1},
  24.                 {1,0,0,0,1,1,0,1,1,1},
  25.                 {1,1,1,1,1,1,0,1,1,1}
  26.             };
  27.            
  28.  
  29.             int x = 1, y = 1, z = 0;
  30.             while (true)
  31.             {
  32.                 Console.Clear();
  33.  
  34.                 for (int i = 0; i < maze.GetLength(0); i++)
  35.                 {
  36.                     for (int j = 0; j < maze.GetLength(1); j++)
  37.                     {
  38.                         for (int k = 0; k < maze.GetLength(2); k++ )
  39.                         {
  40.                             if (maze[i, j] == 0) Console.Write(" ");
  41.                             if (maze[i, j] == 1) Console.Write("$");
  42.                             if (maze[j, k] == 2) Console.Write("%");
  43.                         }
  44.  
  45.                     }
  46.                     Console.WriteLine();
  47.                 }
  48.                
  49.                 Console.CursorLeft = x;
  50.                 Console.CursorTop = y;
  51.                 Console.ForegroundColor = ConsoleColor.Red;
  52.                 Console.Write("&");
  53.                 Console.BackgroundColor = ConsoleColor.Cyan;
  54.                 Console.ForegroundColor = ConsoleColor.Green;
  55.                 Console.BackgroundColor = ConsoleColor.Black;
  56.  
  57.  
  58.  
  59.                 ConsoleKeyInfo ki = Console.ReadKey(true);
  60.                 if (ki.Key == ConsoleKey.Escape) break;
  61.                 if (ki.Key == ConsoleKey.LeftArrow && maze[y, x - 1] == 0) x--;
  62.                 if (ki.Key == ConsoleKey.RightArrow && maze[y, x + 1] == 0) x++;
  63.                 if (ki.Key == ConsoleKey.UpArrow && maze[y - 1, x] == 0) y--;
  64.                 if (ki.Key == ConsoleKey.DownArrow && maze[y + 1, x] == 0) y++;
  65.             }
  66.            
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement