예제 #1
0
파일: Board.cs 프로젝트: Istanful/Snake
        public static void CheckCollision()
        {
            foreach (GameObject gameObject in GameObjects)
            {
                bool anyCollision = GameObjects.Any(g => g.X == gameObject.X && g.Y == gameObject.Y && g.Name != gameObject.Name);
                if (anyCollision)
                {
                    string collidedObject = GameObjects.Find(g => g.X == gameObject.X && g.Y == gameObject.Y && g.Name != gameObject.Name).Name;
                    string collided       = gameObject.Name;

                    CollisionInfo collision;

                    if ((collided.Contains("Snake") && !collidedObject.Contains("Snake")) || (collided.Contains("Fly") && !collidedObject.Contains("Fly")))
                    {
                        collision = CollisionInfo.AteFly;
                    }
                    else
                    {
                        collision = CollisionInfo.AteTail;
                    }

                    Board.collided(collision);
                    return;
                }
            }
        }