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 _31__
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- char symbolPlayer = '@';
- char symbolWall = '#';
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#',' ',' ','#',' ',' ','#',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ','#',' ',' ','#',' ','#',' ',' ',' ','#','#','#','#','#','#','#',' ','#'},
- {'#',' ',' ','#',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ','#',' ',' ',' ',' ','#',' ','#',' ',' ',' ',' ','#','#','#','#','#','#'},
- {'#',' ',' ','#',' ','#',' ',' ','#',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ','#',' ','#',' ',' ','#',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ','#',' ',' ','#',' ','#','#','#','#','#','#','#','#',' ',' ','#'},
- {'#',' ',' ',' ',' ','#',' ',' ','#',' ','#',' ',' ',' ',' ','#',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ','#',' ',' ','#',' ','#',' ',' ',' ',' ','#',' ',' ',' ',' ','#'},
- {'#',' ',' ',' ',' ','#',' ',' ','#',' ','#',' ',' ','#',' ','#',' ',' ','#',' ','#'},
- {'#',' ',' ',' ',' ',' ',' ',' ','#',' ','#','#',' ','#',' ','#',' ',' ','#',' ','#'},
- {'#',' ',' ',' ',' ',' ','#',' ',' ',' ','#',' ',' ','#',' ','#',' ',' ','#',' ','#'},
- {'#',' ',' ','#',' ',' ','#',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ','#',' ','#'},
- {'#',' ',' ','#',' ',' ','#',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ','#',' ','#'},
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- };
- int positionUserX = 1;
- int positionUserY = 9;
- bool isWork = true;
- while (isWork)
- {
- int directionX = 0;
- int directionY = 0;
- Console.SetCursorPosition(0, 0);
- DrawMap(map);
- DrawPlayer(ref positionUserY,ref positionUserX, symbolPlayer);
- ChangeDirection(ref directionX, ref directionY, ref isWork);
- Move(ref map, ref positionUserY, ref positionUserX, ref directionY, ref directionX, ref symbolWall);
- }
- }
- static void DrawMap(char[,] map)
- {
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void DrawPlayer(ref int userY, ref int userX, char pacman)
- {
- Console.SetCursorPosition(userY, userX);
- Console.WriteLine(pacman);
- }
- static void ChangeDirection(ref int directionX, ref int directionY, ref bool isWork)
- {
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- directionX--;
- break;
- case ConsoleKey.DownArrow:
- directionX++;
- break;
- case ConsoleKey.LeftArrow:
- directionY--;
- break;
- case ConsoleKey.RightArrow:
- directionY++;
- break;
- case ConsoleKey.Escape:
- isWork = false;
- break;
- }
- }
- static void Move(ref char[,] map, ref int userY, ref int userX, ref int directionY, ref int directionX, ref char symbol)
- {
- if (map[userX + directionX, userY + directionY] != symbol)
- {
- userX += directionX;
- userY += directionY;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement