using System.Collections.Generic;
using System.Threading.Tasks;
static void Main(string[] args)
Console.WindowHeight = 16;
Console.WindowWidth = 32;
int screenwidth = Console.WindowWidth;
int screenheight = Console.WindowHeight;
Random randomnummer = new Random();
pixel hoofd = new pixel();
hoofd.xpos = screenwidth/2;
hoofd.ypos = screenheight/2;
hoofd.schermkleur = ConsoleColor.Red;
string movement = "RIGHT";
List<int> xposlijf = new List<int>();
List<int> yposlijf = new List<int>();
int berryx = randomnummer.Next(0, screenwidth);
int berryy = randomnummer.Next(0, screenheight);
DateTime tijd = DateTime.Now;
DateTime tijd2 = DateTime.Now;
string buttonpressed = "no";
if (hoofd.xpos == screenwidth-1 || hoofd.xpos == 0 ||hoofd.ypos == screenheight-1 || hoofd.ypos == 0)
for (int i = 0;i< screenwidth; i++)
Console.SetCursorPosition(i, 0);
for (int i = 0; i < screenwidth; i++)
Console.SetCursorPosition(i, screenheight -1);
for (int i = 0; i < screenheight; i++)
Console.SetCursorPosition(0, i);
for (int i = 0; i < screenheight; i++)
Console.SetCursorPosition(screenwidth - 1, i);
Console.ForegroundColor = ConsoleColor.Green;
if (berryx == hoofd.xpos && berryy == hoofd.ypos)
berryx = randomnummer.Next(1, screenwidth-2);
berryy = randomnummer.Next(1, screenheight-2);
for (int i = 0; i < xposlijf.Count(); i++)
Console.SetCursorPosition(xposlijf[i], yposlijf[i]);
if (xposlijf[i] == hoofd.xpos && yposlijf[i] == hoofd.ypos)
Console.SetCursorPosition(hoofd.xpos, hoofd.ypos);
Console.ForegroundColor = hoofd.schermkleur;
Console.SetCursorPosition(berryx, berryy);
Console.ForegroundColor = ConsoleColor.Cyan;
if (tijd2.Subtract(tijd).TotalMilliseconds > 500) { break; }
if (Console.KeyAvailable)
ConsoleKeyInfo toets = Console.ReadKey(true);
if (toets.Key.Equals(ConsoleKey.UpArrow) && movement != "DOWN" && buttonpressed == "no")
if (toets.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no")
if (toets.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no")
if (toets.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no")
xposlijf.Add(hoofd.xpos);
yposlijf.Add(hoofd.ypos);
if (xposlijf.Count() > score)
Console.SetCursorPosition(screenwidth / 5, screenheight / 2);
Console.WriteLine("Game over, Score: "+ score);
Console.SetCursorPosition(screenwidth / 5, screenheight / 2 +1);
public int xpos { get; set; }
public int ypos { get; set; }
public ConsoleColor schermkleur { get; set; }