Example #1
0
 public point OtherPoint(point p)
 {
     if (p == pList.First())
         return pList.Last();
     else
         return pList.First();
 }
Example #2
0
 point NextPoint()
 {
     point head = pList.Last();
     point NextPoint = new point(head);
     NextPoint.Move(1, Direction);
     return NextPoint;
 }
Example #3
0
 public new point IsHit(point head)
 {
     if (head.IsHit(pList.First()))
         return pList.First();
     if (head.IsHit(pList.Last()))
         return pList.Last();
     return null;
 }
Example #4
0
 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();
 }
Example #5
0
 public bool IsHit(point p)
 {
     foreach (var point in pList)
     {
         if (p.IsHit(point))
             return true;
     }
     return false;
 }
Example #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);
            }

        }
Example #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);
            }

        }
Example #8
0
 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();
 }
Example #9
0
 public bool Eat(point food)
 {
     point head = NextPoint();
     if (head.IsHit(food))
     {
         pList.Add(food);
         food.ChangeChar(3);    
         score++;
         return true;
     }
     else
         return false;
 }
Example #10
0
 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;
 }
Example #11
0
File: Game.cs Project: 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);
 }
Example #12
0
 public bool IsHit(point p)
 {
     foreach (var wall in wallList)
     {
         if (wall.IsHit(p))
             return true;
     }
     return false;
 }
Example #13
0
 public bool IsHit(point p)
 {
     return p.x == this.x && p.y == this.y;
 }
Example #14
0
 public point(point p, int s)
 {
     x = p.x;
     y = p.y;
     SetChar(s);
 }
Example #15
0
 public point(point p)
 {
     x = p.x;
     y = p.y;
     s = p.s;
 }
Example #16
0
 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);
 }
Example #17
0
File: Game.cs Project: 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;
 }
Example #18
0
File: Game.cs Project: 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);
            }
        }