Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Lesson5_3
- {
- public static class Render
- {
- public static void RenderUnit(int positionX , int positionY , char unit , ConsoleColor color = ConsoleColor.DarkGray)
- {
- Console.SetCursorPosition(positionX , positionY);
- Console.ForegroundColor = color;
- Console.Write(unit);
- Console.ResetColor();
- }
- }
- public class Unit
- {
- public int PositionX { get; private set; }
- public int PositionY { get; private set; }
- public char UnitChar { get; private set; }
- public Unit(char unitChar , int positionX = 0 , int positionY = 0)
- {
- PositionX = positionX;
- PositionY = positionY;
- UnitChar = unitChar;
- }
- public void StepUnit(int stepX , int stepY)
- {
- PositionX += stepX;
- PositionY += stepY;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Unit unit = new Unit('?' , 9 , 9);
- bool end = false;
- Console.CursorVisible = false;
- do
- {
- Render.RenderUnit(unit.PositionX , unit.PositionY , unit.UnitChar , ConsoleColor.Green);
- ConsoleKeyInfo userInput = Console.ReadKey();
- switch (userInput.Key)
- {
- case ConsoleKey.UpArrow:
- unit.StepUnit(0 , -1);
- break;
- case ConsoleKey.DownArrow:
- unit.StepUnit(0 , 1);
- break;
- case ConsoleKey.LeftArrow:
- unit.StepUnit(-1 , 0);
- break;
- case ConsoleKey.RightArrow:
- unit.StepUnit(1 , 0);
- break;
- case ConsoleKey.Spacebar:
- case ConsoleKey.Enter:
- case ConsoleKey.Escape:
- end = true;
- break;
- }
- Console.Clear();
- }
- while (!end);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement