Trax游戏的函数式编程实现详解
1. Trax基础操作
在Trax游戏中,我们首先需要定义一些基础的操作和函数,用于处理游戏中的坐标、瓦片等元素。
- 坐标移动函数 :定义了向四个方向移动坐标的函数。
north c = {c & row = c.row-1}
south c = {c & row = c.row+1}
west c = {c & col = c.col-1}
east c = {c & col = c.col+1}
go North = north
go South = south
go West = west
go East = east
- Trax属性函数 :用于获取Trax的一些属性,如瓦片数量、坐标范围、维度等。
nr_of_tiles :: !Trax -> Int
nr_of_tiles trax = length trax.tiles
bounds :: !Trax -> (!(!Int,!Int), !(!Int,!Int))
bounds trax
| nr_of_tiles trax > 0 = ((minList cols,maxList cols), (minList rows,maxList rows))
| otherwise = abort "bounds␣appl
超级会员免费看
订阅专栏 解锁全文

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



