Mastering Python design mode learning structure to enjoy the meta-model

Source: Internet
Author: User

I've never used it in my daily life.

Is it really more used in the game industry?

Learn a bit,

Have an impression.

ImportRandom fromEnumImportEnumtreetype= Enum ('Treetye','apple_tree cherry_tree Peach_tree')classTree:pool=dict ()def __new__(CLS, tree_type): obj=Cls.pool.get (Tree_type, None)if  notObj:obj= object.__new__(CLS) Cls.pool[tree_type]=obj Obj.tree_type=Tree_typereturnobjdefrender (self, age, X, y):Print('render a tree of type {} and age {} at ({}, {})'. Format (Self.tree_type, age, X, y))defMain (): Rnd=Random. Random () age_min, Age_max= 1, 30Min_point, Max_point= 0, 100Tree_counter=0 for_inchRange (10): T1=Tree (Treetype.apple_tree) T1.render (Rnd.randint (Age_min, Age_max), Rnd.randint (Min_point, Max _point), Rnd.randint (Min_point, Max_point)) Tree_counter+ = 1 for_inchRange (3): T2=Tree (Treetype.cherry_tree) T2.render (Rnd.randint (Age_min, Age_max), Rnd.randint (Min_point, MA X_point), Rnd.randint (Min_point, Max_point)) Tree_counter+ = 1 for_inchRange (5): T3=Tree (Treetype.peach_tree) T3.render (Rnd.randint (Age_min, Age_max), Rnd.randint (Min_point, Max _point), Rnd.randint (Min_point, Max_point)) Tree_counter+ = 1if __name__=='__main__': Main ()

Mastering Python design mode learning structure to enjoy the meta-model

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.