介业's profile龙虎门PhotosBlogLists Tools Help

Blog


    August 23

    设计snake类

    要设计一个贪吃蛇的游戏。还要是3D的,不管怎么样3D也好,2D也罢,用OOP的思想去设计总不会错^_^
    想了一个下午,在纸上涂了很久,基本算法已经了然于心,说实话算法真的很简单:)主要是要划分好哪几个类,以及考虑到今后可能会有那些扩展~~~~
    整个游戏中会用到的对象不多,大致是:蛇(snake),地图(场景)(scene),食物(food),计分板(panel),障碍物(block)
    其中snake这个类类似于定义一个链表类,因为它有头和尾巴,还会根据吃的东西不停的长大,所以用链表来实现它最合适不过了:)
    food这个类可以先定义成一个抽象类,为什么要这么做?最简单得原因是本人想练习一下使用虚函数和定义抽象类^_^其次昨晚和波哥讨论了一下,他提了若干有用得建议:比如吃了会变长得食物,会变短得,会加速得,会减速得,会变颜色得,会变形状得……所以我想把它定义成抽象基类会比较好扩展:)
    block这个类也可以定义成抽象基类,因为障碍物同样可以以后扩展
    最后整个游戏应该是一个大的类,把其他所有的类对象组织起来进行交互,命名为snakeModel
    下面是snake类的最初手稿:
     

    Comments (2)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    yaliowrote:
    很不错的想法,非常羡慕。。。可否留下联系方式?要向您讨教一下。
    Dec. 12
    飞 徐wrote:
    不错
    Aug. 24

    Trackbacks

    The trackback URL for this entry is:
    http://phoenix-qu.spaces.live.com/blog/cns!28696C550A3403A2!333.trak
    Weblogs that reference this entry
    • None