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 ConsoleApp1
- {
- class Program
- {
- public class Point
- {
- public int x, y;
- public Point()
- {
- y = size / 2;
- x = size;
- }
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- }
- static void Walls(int size)
- {
- for (int i = 0; i <= size + 1; i++)
- {
- Console.SetCursorPosition(i * 2, 0);// Вг
- Console.Write("X");
- Console.SetCursorPosition(0, i);// ЛВ
- Console.Write("X");
- Console.SetCursorPosition(i * 2, size + 1); //Нг
- Console.Write("X");
- Console.SetCursorPosition((size + 1) * 2, i); //Пв
- Console.Write("X ");
- }
- }
- static void GameOver()
- {
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("GAME OVER");
- }
- static int size = 50;
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- Walls(size);
- Random R = new Random();
- Point player = new Point(R.Next(1, size + 1) * 2 - 1, R.Next(1, size + 1));
- Console.SetCursorPosition(player.x, player.y);
- Console.Write("#");
- ConsoleKeyInfo button;
- button = Console.ReadKey(true);
- switch (button.Key)
- {
- case ConsoleKey.W:
- if (player.y == 1)
- {
- GameOver();
- }
- else
- {
- player.y--;
- }
- break;
- case ConsoleKey.A:
- if (player.x == 1)
- {
- GameOver();
- }
- else
- {
- player.y-=2;
- }
- break;
- case ConsoleKey.S:
- if (player.y == size)
- {
- GameOver();
- }
- else
- {
- player.y ++;
- }
- break;
- case ConsoleKey.D:
- if (player.x == size * 2 - 1)
- {
- GameOver();
- }
- else
- {
- player.y +=2;
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement