pygame - python 如何实现 " goto " 功能?
阿神
阿神 2017-04-17 16:52:31
[Python讨论组]
阿神
阿神

闭关修行中......

全部回复(2)
黄舟

https://github.com/snoack/python-goto

from goto import with_goto

@with_goto
def range(start, stop):
    i = start
    result = []

    label .begin
    if i == stop:
        goto .end

    result.append(i)
    i += 1
    goto .begin

    label .end
    return result
阿神

首先,初学者不适合使用任何goto语句,因为这会在不久之后把你的代码变成跳跳糖:)
其次,你可以把游戏页面显示逻辑当做是一种状态,比如把"游戏开始界面"当做是一种状态,然后通过状态机的形式,控制状态的转换。也就是说,在程序遇到"游戏结束"的状态后,立马将程序状态变换成"游戏开始"。听上去很麻烦,但是其实很简单,给你个伪代码:

status_into_game_begin
# run game until touch game over condition
if game_over_condition == true
    status_into_game_over
    status_into_game_begin
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号