Python类各种方法和属性定义

2020-01-05  本文已影响0人  不思九八

定义一个类Game

class Game(object):
    name = "贪吃蛇"

    def __init__(self, player):
        self.player = player
        self.top_score = 267

    @property
    def current_player(self):
        return self.player
 
    @staticmethod
    def show_help():
        print("帮助信息:按Erter键开始游戏。")
 
    @classmethod
    def show_game(cls):
        print(cls.name.center(20, '*'))
 
    def start(self):
        print('{}开始游戏了,他的最高分为{}分。'.format(self.current_player, self.top_score))

Game.show_game()
Game.show_help()
game = Game("Jack")
game.start()

说明:

上一篇 下一篇

猜你喜欢

热点阅读