示例#1
0
        public static void Main(string[] args)
        {
            //TreeFactory fac = new TreeFactory();
            TreeType type = TreeFactory.GetTreeType("Common Tree", "Green", "Woodish");

            Forest forest = new Forest();

            for (int i = 0; i < 100; i++)
            {
                forest.PlantTree(i, i + 10, "Common Tree", "Green", "Woodish");
            }

            foreach (Tree tree in forest.trees)
            {
                tree.Draw();
            }

            Console.WriteLine($"Number of Trees: {forest.trees.Count}");
            Console.WriteLine($"Number of Tree Types: {TreeFactory.NumberOfTreeTypes()}");

            Console.ReadKey();
        }
示例#2
0
        public static TreeType GetTreeType(string name, string color, string texture)
        {
            TreeType found = treeTypes.Find((t) =>
            {
                return(t.Name == name && t.Color == color && t.Texture == texture);
            });

            if (found != null)
            {
                return(found);
            }
            else
            {
                TreeType newType = new TreeType()
                {
                    Name    = name,
                    Color   = color,
                    Texture = texture
                };
                treeTypes.Add(newType);
                return(newType);
            }
        }