Ejemplo n.º 1
0
        public bool is_dir_ok(SnakeDirection dir)
        {
            Point n_point = dir2coord(dir);

            // Wall collision
            if (n_point.X < 0 || n_point.X >= GridWidth || n_point.Y < 0 || n_point.Y >= GridHeight)
            {
                return(false);
            }

            // Snake Collision
            for (int i = 0; i < enemies.Length; i++)
            {
                if (enemies[i].Alive)
                {
                    if (enemies[i].BodyParts.Any(b => b.X == n_point.X && b.Y == n_point.Y))
                    {
                        return(false);
                    }
                }
            }
            if (BodyParts.Take(BodyLength - 1).Any(b => b.X == HeadPosX && b.Y == HeadPosY))
            {
                return(false);
            }

            if (((int)dir + 2) % 4 == (int)Direction)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
            internal bool CheckAlive()
            {
                if (Alive == false)
                {
                    return(this.Alive);
                }

                if (HeadPosX < 0 || HeadPosX >= GridWidth || HeadPosY < 0 || HeadPosY >= GridHeight)
                {
                    this.alive = false;
                    return(this.alive);
                }

                // Check enemy collision
                for (int i = 0; i < enemies.Length; i++)
                {
                    if (enemies[i].bodyParts.Any(b => b.X == HeadPosX && b.Y == HeadPosY))
                    {
                        this.alive = false;
                        break;
                    }
                }

                // Check own colission
                if (BodyParts.Take(BodyLength - 1).Any(b => b.X == HeadPosX && b.Y == HeadPosY))
                {
                    this.alive = false;
                }


                return(this.Alive);
            }