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;
- using System.Threading.Tasks;
- namespace classes3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Renderer renderer = new Renderer();
- Player player = new Player(0, 0);
- player.Move(2, 5);
- renderer.DrawPlayer(player, 'H');
- }
- }
- class Player
- {
- public Player(int positionX, int positionY)
- {
- PositionX = positionX;
- PositionY = positionY;
- }
- public int PositionX { get; private set; }
- public int PositionY { get; private set; }
- public void Move(int offsetX, int offsetY)
- {
- PositionX += offsetX;
- PositionY += offsetY;
- if (PositionX > Console.WindowWidth)
- PositionX = Console.WindowWidth;
- if (PositionY > Console.WindowHeight)
- PositionY = Console.WindowHeight;
- }
- }
- class Renderer
- {
- public void DrawPlayer(Player player, char character, ConsoleColor playerColor = ConsoleColor.Green)
- {
- Console.CursorVisible = false;
- Console.SetCursorPosition(player.PositionX, player.PositionY);
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.ForegroundColor = playerColor;
- Console.Write(character);
- Console.ForegroundColor = defaultColor;
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement