Tengo el siguiente código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Snake
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Snake";
int x, y;
x = 1;
y = 1;
double velocidad = 80;
string snakeHead = "o";
Random randomNumberGenerator = new Random();
Console.WindowHeight = 25;
Console.WindowWidth = 80;
Console.BufferHeight = Console.WindowHeight;
Console.BufferWidth = Console.WindowWidth;
string direccion = "E";
Console.CursorVisible = false;
try
{
for (;;)
{
switch (direccion)
{
case "E":
x++;
break;
case "O":
x--;
break;
case "S":
y++;
break;
case "N":
y--;
break;
}
Console.Clear();
Console.SetCursorPosition(x, y);
Console.Write(snakeHead);
Thread.Sleep(Convert.ToInt32(velocidad));
velocidad = velocidad - 0.050;
if (Console.KeyAvailable)
{
ConsoleKey key = Console.ReadKey(true).Key;
switch (key)
{
case ConsoleKey.DownArrow:
if ((direccion == "E") || (direccion == "O"))
direccion = "S";
break;
case ConsoleKey.LeftArrow:
if ((direccion == "N") || (direccion == "S"))
direccion = "O";
break;
case ConsoleKey.RightArrow:
if ((direccion == "N") || (direccion == "S"))
direccion = "E";
break;
case ConsoleKey.UpArrow:
if ((direccion == "E") || (direccion == "O"))
direccion = "N";
break;
}//fin del switch (key)
}//fin del if (Console.Available)
}
}
catch (Exception)
{
Console.SetCursorPosition(35, 10);
Console.Write("Game Over");
Console.ReadKey();
}
}
}
}