《Dice of Doom 游戏开发全解析》
1. 游戏基础操作与强化机制
在 Dice of Doom 游戏中,从六边形 1 攻击到 3 时, board-attack 会正确更新游戏棋盘,使旧方格上留一个骰子,新占领方格上有两个骰子。
为了给棋盘添加强化骰子,我们需要扫描游戏棋盘,找到能容纳额外骰子的已占领位置并添加骰子。强化骰子的数量取决于玩家上一轮捕获的对手骰子数,因此需要记录剩余的强化骰子数量。
为了遵循函数式风格,我们使用局部递归函数编写 add-new-dice 函数:
(defun add-new-dice (board player spare-dice)
(labels ((f (lst n)
(cond ((null lst) nil)
((zerop n) lst)
(t (let ((cur-player (caar lst))
(cur-dice (cadar lst)))
(if (and (eq cur-player player) (< cur-dice *max-dice*))
(cons (list cur-player (1+ cur-dice))
(f (cdr ls
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



