Match3Kit

一个用于简化三消游戏的库。它可以处理一个坚实的图形网格,并且只在列中溢出它们。

Forest walk

示例

为所有类型的图形创建枚举

typealias MyGrid = Grid<Shape>
typealias MyController = Controller<Shape, Generator<Shape>, Matcher<Shape>>

enum Shapes: String, GridFilling {
    case square
    case circle
    case triangle

    var pattern: Pattern {
        Pattern(indices: [])
    }
}

使用配置创建网格控制器

let controller = MyController(
    size: Size(columns: 6, rows: 6),
    basic: [.square, .circle, .triangle],
    bonuse: [],
    obstacles: []
)

基于控制器生成的网格创建UI

for index in allIndices {
    let cell = controller.grid.cell(at: index)
    setupUI(for: cell, at: index)
}

在用户交互后交换图形

func swap(source: Index, target: Index) {
    if controller.canSwapCell(at: source, with: target) {
        swapUI(source, target)
        if controller.shouldSwapCell(at: source, with: target) {
            let indices = controller.swapAndMatchCell(at: source, with: target)
            let match = controller.match(indices: indices, swapIndices: [source, target], refill: .spill)
            remove(indices)
            spawn(match.spawned)
            spill(match.removed)
        } else {
            swapUI(source, target)
        }
    } 
}

用于

森林漫步

Forest walk

待办事项