示例#1
0
文件: Game.cs 项目: Ihor01/snake
        bool Play(int lvl)
        {
            while (true)
            {
                wall.Draw();
                food.Draw();

                if (Snake.GetScore() == 10 * lvl)
                    return true;

                if (wall.IsHit(Snake) || Snake.IsHitTail())
                {
                    return false;
                }

                if (wall.Portal != null)
                {
                    point p = wall.Portal.IsHit(Snake.GetHead());
                    if (p != null)
                    {
                        Snake.Teleport(wall.Portal.OtherPoint(p));
                    }
                }

                if (Snake.Eat(food))
                {
                    Console.SetCursorPosition(5, height + 3);
                    Console.Write(Snake.GetScore() * speed);
                    food = fp.Next(Snake, wall);
                    food.Draw();
                }

                else
                {
                    Snake.Move();
                }

                Thread.Sleep(delay);

                ctrl CtrlRes = Ctrl.GetCtrl();
                if (CtrlRes == ctrl.Spacebar)
                {
                    while (true)
                    {
                        CtrlRes = Ctrl.GetCtrl();
                        if (CtrlRes == ctrl.Spacebar)
                            break;
                    }
                }
                else if (CtrlRes == ctrl.Escape)
                {
                    return false;
                }
                else if (CtrlRes == ctrl.Insert)
                {
                    food = fp.Next(Snake, wall);
                    food.Draw();
                }
                else
                    Snake.HandleSnake(CtrlRes);
            }
        }
示例#2
0
文件: Game.cs 项目: Ihor01/snake
 public int Start(int lvl)
 {
     Console.Clear();
     Console.SetCursorPosition(width / 2 - 5, height / 2);
     Console.Write("Уровень " + lvl.ToString());
     Thread.Sleep(1000);
     Console.Clear();
     Console.SetCursorPosition(3, height + 2);
     Console.Write("Счет:");
     Console.SetCursorPosition(10, height + 2);
     Console.Write("Уровень:");
     Console.SetCursorPosition(13, height + 3);
     Console.Write(lvl);
     Snake = new snake(pos, 4, direction.RIGHT);
     Console.SetCursorPosition(5, height + 3);
     Console.Write(Snake.GetScore() * speed);
     wall = new walls(width, height, lvl);
     fp = new foodpoint(width, height, 2);
     food = fp.Next(Snake, wall);
     food.Draw();
     Play(1);
     int sc = Snake.GetScore() * speed;
     Snake.ResetScore();
     return sc;
 }