Advertisement
Guest User

Falling Rocks (Game)

a guest
Feb 18th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. class Dwarf
  5. {
  6.     static void Main()
  7.     {
  8.         const int PLAYGROUND_HEIGHT = 26;
  9.         const int PLAYER_POS_Y = PLAYGROUND_HEIGHT - 1;
  10.         int playerPositionX = 38;
  11.         const char player = '@';
  12.         Random generator = new Random();
  13.  
  14.         Console.WindowHeight = PLAYGROUND_HEIGHT;
  15.         Console.BufferHeight = Console.WindowHeight;
  16.         Console.CursorVisible = false;
  17.  
  18.         Console.SetCursorPosition(playerPositionX, PLAYER_POS_Y);
  19.         Console.Write(player);
  20.         Console.WriteLine();
  21.  
  22.         // player movement
  23.         while (true)
  24.         {
  25.             if (Console.KeyAvailable)
  26.             {
  27.                 ConsoleKeyInfo key = Console.ReadKey();
  28.  
  29.                 if (key.Key == ConsoleKey.LeftArrow)
  30.                 {
  31.                     playerPositionX -= 1;
  32.                     if (playerPositionX < 0)
  33.                     {
  34.                         playerPositionX = 0;
  35.                     }
  36.                 }
  37.  
  38.                 if (key.Key == ConsoleKey.RightArrow)
  39.                 {
  40.                     playerPositionX += 1;
  41.                     if (playerPositionX > 79)
  42.                     {
  43.                         playerPositionX = 79;
  44.                     }
  45.                 }
  46.                 Console.Clear();
  47.                 Console.SetCursorPosition(playerPositionX, PLAYER_POS_Y);
  48.                 Console.Write(player);
  49.                 Thread.Sleep(30);
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement