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 Snake1b
- {
- class Program
- {
- public enum Direction { Left, Right, Up, Down}
- static void Main(string[] args)
- {
- ConsoleKeyInfo cki;
- int positionX = 0;
- int positionY = 0;
- Direction direction = Direction.Right;
- Console.Title = "Use arrows to stear! Esc to exit the game.";
- do
- {
- // 1. The endles loop of the life
- while (!Console.KeyAvailable)
- {
- switch (direction) {
- case Direction.Right:
- if (positionX < Console.WindowWidth - 1) positionX++;
- break;
- case Direction.Left:
- if (positionX > 0) positionX--;
- break;
- case Direction.Up:
- if (positionY > 0) positionY--;
- break;
- case Direction.Down:
- if (positionY < Console.WindowHeight) positionY++;
- break;
- }
- Console.Clear();
- Console.SetCursorPosition(positionX, positionY);
- Console.ForegroundColor = ConsoleColor.Gray;
- // Console.BackgroundColor = ConsoleColor.Blue;
- Console.Write("*");
- // Console.WriteLine("Endless loop");
- System.Threading.Thread.Sleep(50);
- }
- // 2. A meteor is passing by
- cki = Console.ReadKey(true);
- switch (cki.Key) {
- case ConsoleKey.LeftArrow:
- // if (positionX > 0) positionX--;
- direction = Direction.Left;
- break;
- case ConsoleKey.RightArrow:
- // if (positionX < Console.WindowWidth - 1) positionX++;
- direction = Direction.Right;
- break;
- case ConsoleKey.UpArrow:
- // if (positionY > 0) positionY--;
- direction = Direction.Up;
- break;
- case ConsoleKey.DownArrow:
- // if (positionY < Console.WindowHeight) positionY++;
- direction = Direction.Down;
- break;
- }
- } while (cki.Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement