1、需求分析
设计一个Game类
属性:
定义一个类属性top_score记录游戏的历史最高分
定义一个实例属性player_name记录当前游戏的玩家姓名
方法:
静态方法show_help显示游戏帮助信息
类方法show_top_score显示历史最高分
实例方法start_game开始当前玩家的游戏
2、实例代码
class Game(object):
# 1、定义类属性top_score
top_score = 0
# 2、定义初始化方法__init__
def __init__(self, player_name):
self.player_name = player_name
# 3、定义静态方法,用于输出帮助信息
@staticmethod
def show_help():
print('游戏帮助信息')
# 4、定义类方法
@classmethod
def show_top_score(cls):
print(f'本游戏历史最高分:{cls.top_score}')
# 5、定义实例方法,start_game()
def start_game(self):
print(f'{self.player_name},游戏开始了,你准备好了么?')
# 实例化类生成实例对象
mario = Game('hepingjingying')
mario.start_game()
# 显示历史最高分
Game.show_top_score()
# 弹出游戏帮助信息
Game.show_help()




















