Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace homework
- {
- class Program
- {
- static void PrintMap(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 Main(string[] args)
- {
- Console.CursorVisible = false;
- const string youLose = "YOU DIED";
- int consoleWidth = Console.WindowWidth, consoleHeight = Console.WindowHeight;
- int score = 0;
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
- {'#','@',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
- };
- int[,] coorX = { { 2, 2 }, { 4, 5 }, { 6, 8 }, { 8, 2 }, { 10, 2 }, { 12, 5 }, { 14, 2 },{ 2, 2 }, { 4, 5 }, { 6, 8 }, { 8, 2 }, { 10, 2 }, { 12, 5 }, { 14, 2 } };
- int userY = 1, userX = 1;
- Random rand = new Random();
- while (true)
- {
- Console.SetCursorPosition(20,1);
- Console.Write("ะกัะตั: "+ score);
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < coorX.GetLength(0); i++)
- {
- map[coorX[i, 0], coorX[i, 1]] = ' ';
- coorX[i, 0]++;
- if (coorX[i, 0] >= map.GetLength(0) - 1)
- {
- coorX[i, 0] = 1;
- coorX[i, 1] = rand.Next(1, 13);
- }
- map[coorX[i, 0], coorX[i, 1]] = 'X';
- }
- PrintMap(map);
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (map[userX - 1, userY] != '#')
- {
- map[userX, userY] = ' ';
- userX--;
- map[userX, userY] = '@';
- }
- break;
- case ConsoleKey.DownArrow:
- if (map[userX + 1, userY] != '#')
- {
- map[userX, userY] = ' ';
- userX++;
- map[userX, userY] = '@';
- }
- break;
- case ConsoleKey.LeftArrow:
- if (map[userX, userY - 1] != '#')
- {
- map[userX, userY] = ' ';
- userY--;
- map[userX, userY] = '@';
- }
- break;
- case ConsoleKey.RightArrow:
- if (map[userX, userY + 1] != '#')
- {
- map[userX, userY] = ' ';
- userY++;
- map[userX, userY] = '@';
- }
- break;
- }
- score++;
- if (map[userX, userY] == 'X' || map[userX - 1, userY] == 'X')
- {
- score = 0;
- Console.Clear();
- Console.SetCursorPosition(consoleWidth / 2 - youLose.Length / 2, consoleHeight / 2);
- Console.WriteLine(youLose);
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement