Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int userY = 4;
- int userX = 5;
- Console.CursorVisible = false;
- bool play = true;
- char[,] map =
- { { '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','O',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ','O',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','O',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','O',' ',' ',' ','#' },
- { '#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- { '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }};
- while (play)
- {
- Map(map);
- Console.SetCursorPosition(userY, userX);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey(true);
- switch (charKey.Key)
- {
- case ConsoleKey.LeftArrow:
- if (map[userX, userY - 1] != '#')
- userY--;
- break;
- case ConsoleKey.RightArrow:
- if (map[userX, userY + 1] != '#')
- userY++;
- break;
- case ConsoleKey.UpArrow:
- if (map[userX - 1, userY] != '#')
- userX--;
- break;
- case ConsoleKey.DownArrow:
- if (map[userX + 1, userY] != '#')
- userX++;
- break;
- }
- if (map[userX, userY] == 'O')
- {
- play = false;
- break;
- }
- }
- Console.Clear();
- Console.WriteLine("Ты провалился в яму!");
- Console.ReadKey();
- }
- public static void Map(char[,] map)
- {
- Console.SetCursorPosition(0, 0);
- for (int x = 0; x < map.GetLength(0); x++)
- {
- for (int y = 0; y < map.GetLength(1); y++)
- {
- Console.Write(map[x, y]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement