2048.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:python- 作者: secondtonone1 项目源码 文件源码
def main(stdscr):
    def init():
        #??????
        game_field.reset()
        return 'Game'

    def not_game(state):
        #?? GameOver ?? Win ???
        game_field.draw(stdscr)
        #????????action??????????????
        action = get_user_action(stdscr)
        responses = defaultdict(lambda: state) #???????????????????????
        responses['Restart'], responses['Exit'] = 'Init', 'Exit' #???????????????
        return responses[action]

    def game():
        #????????
        game_field.draw(stdscr)
        #????????action
        action = get_user_action(stdscr)

        if action == 'Restart':
            return 'Init'
        if action == 'Exit':
            return 'Exit'
        if game_field.move(action): # move successful
            if game_field.is_win():
                return 'Win'
            if game_field.is_gameover():
                return 'Gameover'
        return 'Game'


    state_actions = {
            'Init': init,
            'Win': lambda: not_game('Win'),
            'Gameover': lambda: not_game('Gameover'),
            'Game': game
        }

    curses.use_default_colors()
    game_field = GameField(win=32)


    state = 'Init'

    #???????
    while state != 'Exit':
        state = state_actions[state]()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号