Python Exercises: Simple character Game program

Source: Internet
Author: User

Requirements:
1. Create three game characters, respectively:
Cang Jing, Female, 18, initial combat 1000
Tony Wood, Male, 20, initial combat 1800
Wave Toto, female, 19, initial combat 2500

2, the game scene, respectively:
Bush fights, consumes 200 combat power
Self-cultivation, increased 100 combat effectiveness
Multiplayer game, consumes 500 combat power

class Person:    def __init__(self, name, gender, age, fight):        self.name = name        self.gender = gender        self.age = age        self.fight = fight    def caocong(self):        self.fight = self.fight - 200    def xiulian(self):        self.fight = self.fight + 100    def duoren(self):        self.fight = self.fight - 500    def show(self):        print("%s %s %d %d" %(self.name, self.gender, self.age, self.fight))cang = Person("苍井井", "女", 18, 1000)dong = Person("东尼木木", "男", 20, 1800)bo = Person("波多多", "女", 19, 2500)cang.show()dong.show()bo.show()cang.caocong()dong.xiulian()bo.duoren()cang.show()dong.show()bo.show()运行结果:苍井井 女 18 1000东尼木木 男 20 1800波多多 女 19 2500苍井井 女 18 800东尼木木 男 20 1900波多多 女 19 2000

Python Exercises: Simple character Game program

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.