Esempio n. 1
0
        /// <summary>
        /// Manger
        /// </summary>
        public bool Manger()
        {
            if (Serpents.Tete.X == X && Serpents.Tete.Y == Y)
            {
                Score++;
                SetBalle();

                return(Serpents.Mange());
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// SetBalle
        /// </summary>
        public void SetBalle()
        {
            int    i = 0;
            Random r = new Random();

            X = r.Next(1, Largeur - 1);
            Y = r.Next(1, Hauteur - 1);

            while (Serpents.Any(s => s.X == X && s.Y == Y) && i++ < 5000)
            {
                X = r.Next(1, Largeur - 1);
                Y = r.Next(1, Hauteur - 1);
            }

            Serpents.DX = 0;
            Serpents.DY = 0;
        }
Esempio n. 3
0
        /// <summary>
        /// Mouvement
        /// </summary>
        public bool Mouvement(int cycle)
        {
            if (cycle++ % Vitesse == 0)
            {
                //Depart du serpent
                if (Serpents.DX == 0 && Serpents.DY == 0)
                {
                    Direction();
                }

                //Distance transversal atteint
                if (DistanceX == 0 || DistanceY == 0)
                {
                    Direction();
                }

                //Eviter obstacle
                if (Serpents.Obstacle())
                {
                    if (Serpents.Possibilite() is List <KeyValuePair <int, int> > possibilites)
                    {
                        if (!possibilites.Any())
                        {
                            return(Mort());
                        }

                        Random r     = new Random();
                        int    choix = r.Next(0, possibilites.Count);
                        Direction(possibilites[choix].Key, possibilites[choix].Value);
                    }
                }

                Serpents.Mouvement();
            }

            return(false);
        }