CareerCup Old cell-phones game "snake"

来源:互联网 发布:笔记本电脑选择知乎 编辑:程序博客网 时间:2024/05/04 13:45

Implement in OOP the old cell-phones game "snake". Implement the function "MoveUp". Follow up: how would you reduce space complexity?

--------------------------------------------------



if it's really about the space, you can just store coordinates of the head and the rest of the snake store as a linked list containing the 2bit flag: UP/DOWN/LEFT/RIGHT 

then, when you move the head up, you need to calculate a new position of each "limb" of the snake starting from the head and going down to the tail. Then if it happens that the new position of the head coincides with that of one of the limbs, game is over..Otherwise, you just update 2bit flags in your linked list according to new positions



0 0
原创粉丝点击