Example #1
0
        protected void addFood()
        {
            int  x = 0, y = 0;
            int  buffer     = CSnakePart.Size * 4;
            bool conflicted = true;

            while (conflicted)
            {
                x = rnd.Next(this.Width - buffer - 25);
                if (x == 0)
                {
                    x += buffer + 10;
                }
                y = rnd.Next(this.Height - buffer - 25);
                if (y == 0)
                {
                    y += buffer + 10;
                }

                // check for conflict with snake
                CFood f = new CFood(x, y);
                conflicted = Snake.HitSelf(f.DrawRect);
            }
            _food = new CFood(x, y);
        }
Example #2
0
File: CSnake.cs Project: xmsa/Snake
 //Snake Eating
 void eating(ref CFood _food)
 {
     Add();
     _food.shift();
     if (_frm._flag)
     {
         _frm.TimerShiftFood.Stop();
         _frm.TimerShiftFood.Start();
     }
     _frm._fLx = _food._location.X;
     _frm._fLy = _food._location.Y;
     _frm._score++;
     _frm.Lblscore.Text = _frm._score.ToString();
 }
Example #3
0
File: CSnake.cs Project: xmsa/Snake
        //Check Snake Eating
        public void eatfood(ref CFood _food)
        {
            int _x = _head.X;
            int _y = _head.Y;

            if ((_frm._fLx <= _x + 20 && _x + 20 <= _frm._fLx + 20) && (_frm._fLy <= _y + 20 && _y + 20 <= _frm._fLy + 20))
            {
                eating(ref _food);
            }
            else if ((_frm._fLx <= _x && _x <= _frm._fLx + 20) && (_frm._fLy <= _y + 20 && _y + 20 <= _frm._fLy + 20))
            {
                eating(ref _food);
            }
            else if ((_frm._fLx <= _x + 20 && _x + 20 <= _frm._fLx + 20) && (_frm._fLy <= _y && _y <= _frm._fLy + 20))
            {
                eating(ref _food);
            }
            else if ((_frm._fLx <= _x && _x <= _frm._fLx + 20) && (_frm._fLy <= _y && _y <= _frm._fLy + 20))
            {
                eating(ref _food);
            }
        }
Example #4
0
 //Constructor
 public Frm_Main()
 {
     new Frm_Login().ShowDialog();
     _Frm_Main = this;
     InitializeComponent();
     PanelEnd.Dock    = DockStyle.Fill;
     PanelEnd.Visible = false;
     _food            = new CFood(ref _Frm_Main);
     _score           = 0;
     _snake           = new CSnake(ref _Frm_Main, Keys.D);
     _fLx             = _food._location.X;
     _fLy             = _food._location.Y;
     new Frm_Setting(ref _Frm_Main).ShowDialog();
     TimerSpeed.Interval = 1010 - ((_Speed - 1) * 50);
     if (_ShiftFood != 0)
     {
         TimerShiftFood.Interval = 10000 - ((_ShiftFood - 1) * 450);
         _flag = true;
     }
     else
     {
         _flag = false;
     }
 }
Example #5
0
        public bool CanEatFood(CFood __f)
        {
            CSnakePart head = Body[0];

            return(head.DrawRect.IntersectsWith(__f.DrawRect));
        }