static public bool IsEaten(List <Snake> snakes, Foods f)
        {
            int sX = snakes[0].Location.X, sY = snakes[0].Location.Y;
            int fX = f.Location.X, fY = f.Location.Y;

            if (sX < fX + 30 && sX > fX - 30 && sY < fY + 20 && sY > fY - 20)
            {
                SoundPlayer sp = new SoundPlayer(Properties.Resources.eat);
                sp.Play();
                Snake s = snakes.Last();
                switch (s.Dir)
                {
                case Snake.Direction.Up:
                    snakes.Add(new Snake(new Point(s.Location.X, s.Location.Y + 60), s.Speed, s.Dir));
                    break;

                case Snake.Direction.Down:
                    snakes.Add(new Snake(new Point(s.Location.X, s.Location.Y - 60), s.Speed, s.Dir));
                    break;

                case Snake.Direction.Left:
                    snakes.Add(new Snake(new Point(s.Location.X + 60, s.Location.Y), s.Speed, s.Dir));
                    break;

                default:
                    snakes.Add(new Snake(new Point(s.Location.X - 60, s.Location.Y), s.Speed, s.Dir));
                    break;
                }

                return(true);
            }
            return(false);
        }
Esempio n. 2
0
 private void InitiSnake()
 {
     snakes.Clear();
     ocus.Clear();
     Snake.S     = null;
     replayfoods = true;
     foreach (Snake s in MainWays.InitiSnakes(new Point(600, 240), 10))
     {
         snakes.Add(s);
     }
     rand        = new Random();
     f           = new Foods(this.Size, rand);
     tmr.Enabled = true;
     //SoundPlayer sp = new SoundPlayer(Properties.Resources.gamebg);
     //sp.Play();
 }