using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleAppSnake
public bool Equals(P other)
return this.x == other.x && this.y == other.y;
public static P operator+(P a, P b)
return new P(a.x + b.x, a.y + b.y);
public static P operator -(P a, P b)
return new P(a.x - b.x, a.y - b.y);
static readonly P[] dirs = new[] { new P(0,1), new P(1,0), new P(0,-1), new P(-1,0) };
const int fieldSize = 10;
const int snakeStartLength = 5;
const Dir snakeStartDir = Dir.D;
static readonly P snakeStartPosition = new P(2, fieldSize / 2);
static int[,] field = new int[fieldSize, fieldSize];
static LinkedList<P> snake;
snake = new LinkedList<P>();
snakeDir = snakeStartDir;
P p = snakeStartPosition;
for (int i = 0; i < snakeStartLength; i++)
p = p + dirs[(int)snakeStartDir];
static bool IsInsideField(P p)
return p.x >= 0 && p.x < fieldSize && p.y >= 0 && p.y < fieldSize;
P newHead = head + dirs[(int)snakeDir];
if (!IsInsideField(newHead))
static void ClearRender()
for (int i = 0; i < fieldSize; i++)
for (int j = 0; j < fieldSize; j++)
field[head.y, head.x] = 2;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fieldSize; i++)
for (int j = 0; j < fieldSize; j++)
sb.Append(field[i, j].ToString());
Console.WriteLine(sb.ToString());
Console.WriteLine("------------wsad, enter");
public static void Main(string[] args)
string s = Console.ReadLine().ToUpper();
if (Enum.TryParse<Dir>(s, out d))
if(!(dirs[(int)d] + dirs[(int)snakeDir]).Equals(new P(0,0)))
Console.WriteLine("Вы въебались!");
Console.WriteLine("------------------");