I am trying to make a snake game in a c# console application.
using System.Reflection;
namespace First_console_game
{
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
int redo = 0;
Byte Foods = 0;
Byte Flops = 0;
int x = 10, y = 20;
int Foodx = rnd.Next(1, 200);
int Foody = rnd.Next(1, 175);
ConsoleKeyInfo keyInfo;
do
{
keyInfo = Console.ReadKey(true);
//Console.SetCursorPosition(Foodx, Foody); This is the position of the food cell, and this is the part where it doesn't work.
Flops += 1;
if (Flops == 5)
{
Console.Clear();
Flops = 0;
}
switch (keyInfo.Key)
{
case ConsoleKey.RightArrow:
x += 1;
Console.SetCursorPosition(x, y);
Console.Write("x");
break;
case ConsoleKey.LeftArrow:
x--;
Console.SetCursorPosition(x, y);
Console.Write("x");
break;
case ConsoleKey.UpArrow:
y -= 1;
Console.SetCursorPosition(x, y);
Console.Write("^");
break;
case ConsoleKey.DownArrow:
y += 1;
Console.SetCursorPosition(x, y);
Console.Write("x");
break;
}
} while (redo == 0);
Console.ReadLine();
}
}
}
In the game, I want to have two cursors. One for the food, and one for the player.
But obviously, I can't use Console.SetCursorPosition(Foodx, Foody)
because that will drive the player all around the screen, and therefore mess up the game.
So how do I add a separate cursor? Thanks.