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 Tasks
- {
- class Program
- {
- static void Main(string[] args)
- {
- char[,] map = { { '*', '*', '*', '*', '*','*', '*', '*', '*', '*', '*' },
- { '*', ' ', ' ', ' ', '*',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', ' ', ' ', '*',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', ' ', ' ', '*',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', '*', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
- { '*', ' ', '*', ' ', ' ',' ', ' ', ' ', '*', ' ', '*' },
- { '*', ' ', '*', ' ', ' ',' ', ' ', ' ', '*', ' ', '*' },
- { '*', '*', '*', '*', '*','*', '*', '*', '*', '*', '*' }};
- Console.CursorVisible = false;
- int userX = 6, userY = 6;
- while (true)
- {
- DrawMap(ref map);
- Console.SetCursorPosition(userY, userX);
- Console.Write("$");
- ConsoleKeyInfo playerKey = Console.ReadKey();
- MovePlayer(playerKey, ref map,ref userX, ref userY);
- Console.Clear();
- }
- }
- static void DrawMap(ref char[,] array)
- {
- for (int i = 0; i < array.GetLength(0); i++)
- {
- for (int j = 0; j < array.GetLength(1); j++)
- {
- Console.Write(array[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void MovePlayer (ConsoleKeyInfo playerInput, ref char [,] playGround, ref int xposition, ref int yPosition)
- {
- switch (playerInput.Key)
- {
- case ConsoleKey.UpArrow:
- if (playGround[xposition - 1, yPosition] != '*')
- {
- xposition--;
- }
- break;
- case ConsoleKey.DownArrow:
- if (playGround[xposition + 1, yPosition] != '*')
- {
- xposition++;
- }
- break;
- case ConsoleKey.LeftArrow:
- if (playGround[xposition, yPosition - 1] != '*')
- {
- yPosition--;
- }
- break;
- case ConsoleKey.RightArrow:
- if (playGround[xposition, yPosition + 1] != '*')
- {
- yPosition++;
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement