Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- class Dwarf
- {
- static void Main()
- {
- const int PLAYGROUND_HEIGHT = 26;
- const int PLAYER_POS_Y = PLAYGROUND_HEIGHT - 1;
- int playerPositionX = 38;
- const char player = '@';
- Random generator = new Random();
- Console.WindowHeight = PLAYGROUND_HEIGHT;
- Console.BufferHeight = Console.WindowHeight;
- Console.CursorVisible = false;
- Console.SetCursorPosition(playerPositionX, PLAYER_POS_Y);
- Console.Write(player);
- Console.WriteLine();
- // player movement
- while (true)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo key = Console.ReadKey();
- if (key.Key == ConsoleKey.LeftArrow)
- {
- playerPositionX -= 1;
- if (playerPositionX < 0)
- {
- playerPositionX = 0;
- }
- }
- if (key.Key == ConsoleKey.RightArrow)
- {
- playerPositionX += 1;
- if (playerPositionX > 79)
- {
- playerPositionX = 79;
- }
- }
- Console.Clear();
- Console.SetCursorPosition(playerPositionX, PLAYER_POS_Y);
- Console.Write(player);
- Thread.Sleep(30);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement