示例#1
0
文件: portal.cs 项目: Ihor01/snake
 public point OtherPoint(point p)
 {
     if (p == pList.First())
         return pList.Last();
     else
         return pList.First();
 }
示例#2
0
文件: snake.cs 项目: Ihor01/snake
 point NextPoint()
 {
     point head = pList.Last();
     point NextPoint = new point(head);
     NextPoint.Move(1, Direction);
     return NextPoint;
 }
示例#3
0
文件: portal.cs 项目: Ihor01/snake
 public new point IsHit(point head)
 {
     if (head.IsHit(pList.First()))
         return pList.First();
     if (head.IsHit(pList.Last()))
         return pList.Last();
     return null;
 }
示例#4
0
文件: portal.cs 项目: Ihor01/snake
 public portal(int x1, int y1, int x2, int y2)
 {
     pList = new List<point>();
     point port1 = new point(x1, y1, 5);
     pList.Add(port1);
     point port2 = new point(x2, y2, 5);
     pList.Add(port2);
     Draw();
 }
示例#5
0
文件: figure.cs 项目: Ihor01/snake
 public bool IsHit(point p)
 {
     foreach (var point in pList)
     {
         if (p.IsHit(point))
             return true;
     }
     return false;
 }
示例#6
0
        public line_vertical(int yu, int yd, int x, int s)
        {
            pList = new List<point>();
            for (int y = yu; y <= yd; y++)
            {
                point p = new point(x, y, s);
                pList.Add(p);
            }

        }
示例#7
0
        public line_horizontal(int xl, int xr, int y, int s)
        {
            pList = new List<point>();
            for (int x = xl; x <= xr; x++)
            {
                point p = new point(x, y, s);
                pList.Add(p);
            }

        }
示例#8
0
文件: snake.cs 项目: Ihor01/snake
 public snake(point pos, int length, direction dir)
 {
     Direction = dir;
     pList = new List<point>();
     for (int i = 0; i < length; i++)
     {
         point p = new point(pos);
         p.Move(i, dir);
         pList.Add(p);
     }
     Draw();
 }
示例#9
0
文件: snake.cs 项目: Ihor01/snake
 public bool Eat(point food)
 {
     point head = NextPoint();
     if (head.IsHit(food))
     {
         pList.Add(food);
         food.ChangeChar(3);    
         score++;
         return true;
     }
     else
         return false;
 }
示例#10
0
文件: foodpoint.cs 项目: Ihor01/snake
 public point Next(snake Snake, walls wall)
 {
     int x;
     int y;
     point p;
     do
     {
         x = rnd.Next(1, whidth - 1);
         y = rnd.Next(1, height - 1);
         p = new point(x, y, s);
     } while (Snake.IsHit(p) || wall.IsHit(p));
     return p;
 }
示例#11
0
文件: Game.cs 项目: Ihor01/snake
 public Game(int width, int height, int speed)
 {
     this.width = width;
     this.height = height;
     if (speed == 1)
         delay = 300;
     else if (speed == 2)
         delay = 200;
     else if (speed == 3)
         delay = 100;
     else if (speed == 4)
         delay = 50;
     else if (speed == 5)
         delay = 25;
     this.speed = speed;
     pos = new point(11, 11, 3);
 }
示例#12
0
文件: walls.cs 项目: Ihor01/snake
 public bool IsHit(point p)
 {
     foreach (var wall in wallList)
     {
         if (wall.IsHit(p))
             return true;
     }
     return false;
 }
示例#13
0
文件: point.cs 项目: Ihor01/snake
 public bool IsHit(point p)
 {
     return p.x == this.x && p.y == this.y;
 }
示例#14
0
文件: point.cs 项目: Ihor01/snake
 public point(point p, int s)
 {
     x = p.x;
     y = p.y;
     SetChar(s);
 }
示例#15
0
文件: point.cs 项目: Ihor01/snake
 public point(point p)
 {
     x = p.x;
     y = p.y;
     s = p.s;
 }
示例#16
0
文件: snake.cs 项目: Ihor01/snake
 public void Teleport(point port)
 {
     var tail = pList.Last();
     pList.Remove(tail);
     tail.Clear();
     var head = new point(port, 3);
     head.Move(1, Direction);
     pList.Add(head);
 }
示例#17
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;
 }
示例#18
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);
            }
        }