設計運動我想提高我的遊戲開發設計,現在我有這樣的事情:提高對貪吃蛇遊戲
class Movement {
private:
Body b;
public:
move_up() {
// catch the body head
// add one snake character above head
// catch the body tail
// remove the tail character
}
move_down(){
// catch the body head
// add one snake character below head
// catch the body tail
// remove the tail character
}
move_left(){
// catch the body head
// add one snake character on left side of head
// catch the body tail
// remove the tail character
}
move_right(){
// catch the body head
// add one snake character on right side of head
// catch the body tail
// remove the tail character
}
}
這是非常醜陋的,看看每次移動方法內repetead僞代碼。我想讓這個更通用,但我不知道如何在C++中完成它。有什麼建議麼?
做一個'移動'函數,它將一個枚舉作爲參數(指示哪條路要走)? – UnholySheep