alex566/Match3Kit
Library for simple Match3 games.
Example
Create the enum for all kinds of figures:
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: [])
}
}Create a grid controller with configurations:
let controller = MyController(
size: Size(columns: 6, rows: 6),
basic: [.square, .circle, .triangle],
bonuse: [],
obstacles: []
)Create UI based on the grid that the controller generated:
for index in allIndices {
let cell = controller.grid.cell(at: index)
setupUI(for: cell, at: index)
}Swap figures after the user interaction:
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)
}
}
}Used in:
Forest walk
[[Forest walk]](https://apps.apple.com/app/apple-store/id1513811419?pt=120889283&ct=match3kit&mt=8 "Forest walk")
TODO:
- Add more examples with bonuses
- Add a demo project
Package Metadata
Repository: alex566/Match3Kit
Stars: 46
Forks: 9
Open issues: 0
Default branch: master
Primary language: swift
License: MIT
Topics: casual-game, game, gamedev, ios-swift, match-3, match3, match3-game, spm, swift-package-manager, swift5
README: README.md