C# 使蛇类游戏成为记分器并提高移动速度

C# 使蛇类游戏成为记分器并提高移动速度,c#,C#,因此,我制作了这个简单的蛇游戏,作为一个学校项目,现在我想通过添加分数计数器来改进它,并在每次获得食物帮助时提高蛇的移动速度,非常感谢 这就是我目前面临的问题 名称空间蛇 { 班级计划 { 静态void Main(字符串[]参数) { Console.WindowHeight=32; Console.WindowWidth=64; int screenwidth=Console.WindowWidth; int screenheight=Console.WindowHeight; Random

因此,我制作了这个简单的蛇游戏,作为一个学校项目,现在我想通过添加分数计数器来改进它,并在每次获得食物帮助时提高蛇的移动速度,非常感谢
这就是我目前面临的问题

名称空间蛇
{
班级计划
{
静态void Main(字符串[]参数)
{
Console.WindowHeight=32;
Console.WindowWidth=64;
int screenwidth=Console.WindowWidth;
int screenheight=Console.WindowHeight;
Random randomnummer=新的Random();
int-emtiaz=5;
int-bakht=0;
像素gz=新像素();
gz.xpos=屏幕宽度/2;
gz.ypos=屏幕高度/2;
gz.rangsafe=控制台颜色.Red;
字符串移动=“右”;
List xposlijf=新列表();
List yposlijf=新列表();
int-berryx=randomnumer.Next(0,屏幕宽度);
int-berryy=randomnumer.Next(0,屏幕高度);
DateTime tijd=DateTime.Now;
DateTime tijd2=DateTime.Now;
字符串按钮按下=“否”;
while(true)
{
Console.Clear();
如果(gz.xpos==screenwidth-1 | | gz.xpos==0 | | gz.ypos==screenheight-1 | | gz.ypos==0)
{
bakht=1;
}
对于(int i=0;i500){break;}
如果(控制台键可用)
{
ConsoleKeyInfo-toets=Console.ReadKey(true);
if(toets.Key.Equals(ConsoleKey.UpArrow)&&movement!=“向下”&&buttonpressed==“否”)
{
运动=“向上”;
按钮按下=“是”;
}
if(toets.Key.Equals(ConsoleKey.DownArrow)&&movement!=“向上”&&buttonpressed==“否”)
{
移动=“向下”;
按钮按下=“是”;
}
if(toets.Key.Equals(ConsoleKey.LeftArrow)&&movement!=“RIGHT”&&buttonpressed==“no”)
{
运动=“左”;
按钮按下=“是”;
}
if(toets.Key.Equals(ConsoleKey.RightArrow)&&movement!=“左”&&buttonpressed==“否”)
{
运动=“右”;
按钮按下=“是”;
}
}
}
xposlijf.Add(gz.xpos);
yposlijf.Add(gz.ypos);
开关(移动)
{
案例“UP”:
gz.ypos--;
打破
案例“向下”:
gz.ypos++;
打破
案例“左”:
gz.xpos--;
打破
案例“权利”:
xpos++;
打破
}
if(xposlijf.Count()>emtiaz)
{
xposlijf.RemoveAt(0);
yposlijf.RemoveAt(0);
}
}
控制台。设置光标位置(屏幕宽度/5,屏幕高度/2);
Console.WriteLine(“bazi-ra-bakhti,emtiaz:+emtiaz”);
控制台。设置光标位置(屏幕宽度/5,屏幕高度/2+1);
}
类像素
{
公共int xpos{get;set;}
公共int ypos{get;set;}
公共控制台颜色rangsafe{get;set;}
}
}
}
看看
namespace Snake
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WindowHeight = 32;
            Console.WindowWidth = 64;
            int screenwidth = Console.WindowWidth;
            int screenheight = Console.WindowHeight;
            Random randomnummer = new Random();
            int emtiaz = 5;
            int bakht = 0;
            pixel gz = new pixel();
            gz.xpos = screenwidth / 2;
            gz.ypos = screenheight / 2;
            gz.rangsafe = 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";
            while (true)
            {
                Console.Clear();
                if (gz.xpos == screenwidth - 1 || gz.xpos == 0 || gz.ypos == screenheight - 1 || gz.ypos == 0)
                {
                    bakht = 1;
                }
                for (int i = 0; i < screenwidth; i++)
                {
                    Console.SetCursorPosition(i, 0);
                    Console.Write("*");
                }
                for (int i = 0; i < screenwidth; i++)
                {
                    Console.SetCursorPosition(i, screenheight - 1);
                    Console.Write("*");
                }
                for (int i = 0; i < screenheight; i++)
                {
                    Console.SetCursorPosition(0, i);
                    Console.Write("*");
                }
                for (int i = 0; i < screenheight; i++)
                {
                    Console.SetCursorPosition(screenwidth - 1, i);
                    Console.Write("v");
                }
                Console.ForegroundColor = ConsoleColor.Green;
                if (berryx == gz.xpos && berryy == gz.ypos)
                {
                    emtiaz++;
                    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]);
                    Console.Write("*");
                    if (xposlijf[i] == gz.xpos && yposlijf[i] == gz.ypos)
                    {
                        bakht = 1;
                    }
                }
                if (bakht == 1)
                {
                    break;
                }
                Console.SetCursorPosition(gz.xpos, gz.ypos);
                Console.ForegroundColor = gz.rangsafe;
                Console.Write("*");
                Console.SetCursorPosition(berryx, berryy);
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.Write("*");
                tijd = DateTime.Now;
                buttonpressed = "no";
                while (true)
                {
                    tijd2 = DateTime.Now;
                    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")
                        {
                            movement = "UP";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no")
                        {
                            movement = "DOWN";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no")
                        {
                            movement = "LEFT";
                            buttonpressed = "yes";
                        }
                        if (toets.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no")
                        {
                            movement = "RIGHT";
                            buttonpressed = "yes";
                        }
                    }
                }
                xposlijf.Add(gz.xpos);
                yposlijf.Add(gz.ypos);
                switch (movement)
                {
                    case "UP":
                        gz.ypos--;
                        break;
                    case "DOWN":
                        gz.ypos++;
                        break;
                    case "LEFT":
                        gz.xpos--;
                        break;
                    case "RIGHT":
                        gz.xpos++;
                        break;
                }
                if (xposlijf.Count() > emtiaz)
                {
                    xposlijf.RemoveAt(0);
                    yposlijf.RemoveAt(0);
                }
            }
            Console.SetCursorPosition(screenwidth / 5, screenheight / 2);
            Console.WriteLine("bazi ra bakhti, emtiaz: " + emtiaz);
            Console.SetCursorPosition(screenwidth / 5, screenheight / 2 + 1);
        }
        class pixel
        {
            public int xpos { get; set; }
            public int ypos { get; set; }
            public ConsoleColor rangsafe { get; set; }
        }
    }
}
if (tijd2.Subtract(tijd).TotalMilliseconds > 500)
if (berryx == gz.xpos && berryy == gz.ypos)
{
  emtiaz++;
  berryx = randomnummer.Next(1, screenwidth - 2);
  berryy = randomnummer.Next(1, screenheight - 2);
}