Example #1
0
        private static void DisplayRoomObjects()
        {
            var ordinary = new List <Object>();
            int total    = 0;

            var objects = ObjectMap.GetObjects(Location);

            foreach (var obj in objects)
            {
                if (obj.Scenery && obj.Describe == null)
                {
                    continue;
                }

                if (obj.Static)
                {
                    if (obj is Door door)
                    {
                        if (door.WhenOpen != null && door.Open)
                        {
                            Output.Print($"\n{door.WhenOpen}");
                            continue;
                        }
                        else if (door.WhenClosed != null && !door.Open)
                        {
                            Output.Print($"\n{door.WhenClosed}");
                            continue;
                        }
                    }

                    if (obj.Describe == null && obj.InitialDescription == null)
                    {
                        continue;
                    }
                }

                total++;

                if (!obj.Touched && !string.IsNullOrEmpty(obj.InitialDescription))
                {
                    Output.PrintLine();
                    Output.Print(obj.InitialDescription);
                }
                else if (obj.Describe != null && (obj as Container) == null)
                {
                    Output.PrintLine();
                    Output.Print(obj.Describe());
                }
                else
                {
                    ordinary.Add(obj);
                }
            }

            var group = new StringBuilder();

            if (total > ordinary.Count)
            {
                group.Append("You can also see ");
            }
            else
            {
                group.Append("You can see ");
            }

            for (int i = 0; i < ordinary.Count; i++)
            {
                Object obj = ordinary[i];

                if (i == ordinary.Count - 1 && i > 0)
                {
                    group.Append(" and ");
                }
                else if (i > 0)
                {
                    group.Append(", ");
                }

                if (obj is Container container)
                {
                    if (container.Contents.Count > 0)
                    {
                        Object child = container.Contents[0];
                        group.AppendFormat("{0} {1} (which contains {2} {3})", obj.Article, obj.Name, child.Article, child.Name);
                    }
                    else
                    {
                        group.AppendFormat("{0} {1} (which is empty)", obj.Article, obj.Name);
                    }
                }
                else
                {
                    group.AppendFormat("{0} {1}", obj.Article, obj.Name);
                }
            }

            group.Append(" here.");

            if (ordinary.Count > 0)
            {
                Output.PrintLine();
                Output.Print(group.ToString());
            }
        }
Example #2
0
        public static bool Has <T>() where T : Object
        {
            var objects = ObjectMap.GetObjects(Location);

            return(objects.Any(obj => obj is T));
        }