Python uses classes to build roles in CS games

Source: Internet
Author: User

Learning Points of knowledge:

Class

constructor function

Destructors

Private methods, private properties

class variables

Instance variable

1 #__*__ coding:utf-8 __*__2 __author__="david.z"3 4 classRole:5n = 123#class Variables6n_list=[]7Name ="I am the class name"8     def __init__(self,name,role,weapon,life_value=100,money=15000):9         #constructor FunctionTen         #do some initialization of classes at instantiation One  ASelf.name = Name#r1.name=name instance variable (static property), scope is the instance itself -Self.role =role -Self.weapon =Weapon theSelf.__life_value=Life_value -Self.money = Money -     def __del__(self):# Destructors -         Print("%s was completely dead ... "%self.name) +     defShow_status (self): -         Print("name:%s weapon:%s life_value:%s"% (self.name,self.weapon,self.__life_value)) +     defShot (self): A         Print("Shooting ...") at     defGot_shot (self): -Self.__life_value-= 50 -         Print("%s:ah...,i got shot ..."%self.name) -  -     defBuy_gun (self,gun_name): -         Print("%s just bought%s"%(self.name,gun_name)) inR1 = Role ('Chenronghua','Police','AK47') -R1.buy_gun ("AK47") to r1.got_shot () +  - Print(R1.show_status ()) the  *r2 = Role ('Jack','Terrorist','B22') $R2.got_shot ()

Python uses classes to build roles in CS games

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.