python游戏程序中游戏对象是什么_python,面向对象编程的第1个小应用程序,游戏人生...

应用python面向对象的基本功能,实现下面的"游戏人生"小程序

classperson:def __init__(self,name,gender,age,arg):

self.name=name

self.gender=gender

self.age=age

self.arg=argprint("Initiate status is:")

self.show_status()defgrass_fight(self):

self.arg-= 200self.show_status()defself_exercize(self):

self.arg+= 100self.show_status()defmulti_person(self):

self.arg-= 500self.show_status()defshow_status(self):print(self.name,self.gender,self.age,‘The current fight-value is:‘+str(self.arg))defprocessing(choice):if choice == ‘1‘:

cjj.grass_fight()elif choice == ‘2‘:

cjj.self_exercize()elif choice == ‘3‘:

cjj.multi_person()elif choice == ‘4‘:

exit(‘Game Over‘)else:print(‘please re-input your choice‘)returncjj= person(‘cjj‘,‘female‘,‘18‘,1000)print(‘‘.center(50,‘-‘))whileTrue:print(‘1. grass fighting‘)print(‘2. self-exercizing‘)print(‘3. multi-people‘)print(‘4. Exit‘)

choice= input(‘Input your choice‘)

processing(choice)

运行结果如下:

Initiate status is:

cjj female 18 The current fight-value is:1000

--------------------------------------------------

1. grass fighting

2. self-exercizing

3. multi-people

4. Exit

Input your choice1

cjj female 18 The current fight-value is:800

用户输入选择后,显示当前战斗力,直到用户输入4,游戏结束,显示"Game Over"

原文地址:https://www.cnblogs.com/iceberg710815/p/12000492.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值