match3

command
v0.4.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gem Garden

A match-3 puzzle game built with NSGo and github.com/nsgo-dev/game, made from the match3 template.

Swap two neighboring gems to line up three or more of a color. Four in a line make a line gem, which clears its row or column; an L or a T makes a bomb gem, which clears the cells around it; five in a line make a color gem, which clears every gem of the color it is swapped with, and two special gems swapped together combine. Each level has a move budget and one or more goals: reach a score, collect gems of a color, clear every jelly, or break crates and ice. Meet every goal before the moves run out to win; moves left over add to the score, and the score earns one to three stars.

Twenty levels sit on a level map in two packs, Meadow and Grotto; winning a level unlocks the next, and winning every Meadow level opens the Grotto. Starting a level takes one of five lives, winning gives it back, and a spent life comes back every 20 minutes, also while the game is closed. Stars earned for the first time pay coins, which buy a booster before a level (a line gem, a bomb gem or three more moves) or five more moves when a level runs out. There are no real-money purchases.

It demonstrates:

  • Levels in the versioned match3 level format, one file per level in levels/*.level.yaml, and the packs, star thresholds and unlock rules in a progression manifest, levels/packs.yaml; both are read strictly and kept in the canonical form their encoders write.
  • The rules from pkg/match3: matches of every shape, special gems and their combinations, jelly, crates and ice, cascades, hints and reshuffles of a board with no moves, all deterministic for a seed.
  • Lives on an idle.Meter that refills on the wall clock while the app is closed, and best results and unlocks from progression.Progress, saved with save.Store.
  • The coins, boosters and the out-of-moves offer in economy.yaml.
  • A fixed-step game.Loop that reads input.Actions, bound from the input map in game.yaml, and animates swaps, clears and falls with tween.
  • Native NSGo controls for the map, the counters and the dialogs, over a board drawn on a core.Canvas with no image files.
  • Headless tests that play level 1 to a win and to a loss through nsgotest by touch, the mouse, the keyboard and a game controller, and a bot that wins every level within its moves.

Controls

Keyboard Game controller Touch and mouse
Move the cursor Arrow keys or WASD D-pad or left stick
Select a gem Enter or Space South Tap or click it
Swap the selected gem Arrow keys or WASD D-pad or left stick Tap or click a neighbor, or swipe from the gem
Show a hint H North Hint
Pause Escape East Pause
Turn the map's pack Q and E Shoulders ◀ and ▶
Choose in a dialog Arrows, then Enter D-pad, then South The button

The keyboard and game controller bindings are the input map in game.yaml; edit them there. The swipes are bound in newGemGame.

The game's settings live in game.yaml, its project file. Edit the name and identifier there before shipping it, then write them into nsgo.yaml and check the project:

go run github.com/nsgo-dev/game/cmd/game project sync
go run github.com/nsgo-dev/game/cmd/game project check

Running and testing

Run with hot reload on your desktop (macOS, Windows or Linux):

go tool nsgo dev

Run on other targets:

go tool nsgo dev -target web
go tool nsgo dev -target ios_simulator
go tool nsgo dev -target android

Debug the game's Go code with Delve (dlv on PATH):

go tool nsgo dev -target native -debug

Attach from VS Code with the Attach to game configuration in .vscode/launch.json, replacing 40000 with the port in Delve's API server listening at line, or from GoLand with a Go Remote configuration at the same host and port.

Run the tests, which play level 1 and have a bot win every level:

go tool nsgo test ./...

Vet and check across platforms:

go tool nsgo check -target macos,windows,linux,android,web
go tool nsgo check -target ios,ios_simulator   # on macOS with Xcode

Build release artifacts into dist/ (go tool game release sets GOFLAGS=-tags=release automatically to strip debug code):

GOFLAGS=-tags=release go tool nsgo build -target macos_arm64,windows_x64,linux_x64,web
GOFLAGS=-tags=release go tool nsgo build -target ios,android_arm64

Adding a level

Write the level in levels/<id>.level.yaml in the match-3 level format: its size, colors, seed, moves, an optional mask of holes, its jelly, crates and ice, and its goals. The game draws up to six colors and plays move-budget levels with score, collect, clear-jelly and clear-blocker goals.

Then list it in levels/packs.yaml, the progression manifest, under its pack: its id, which the save keys its stars by, so keep it when renaming or moving the level; its name in each language; its file; stars, the final scores (score plus 250 for each move left) that earn two and three stars, as any win earns one; and unlock, usually after the level before it.

TestBotWinsEveryLevel fails when a level cannot be won within its moves in any of its seeds; TestLevelFilesAreCanonical prints a file's canonical form when it is not in it.

Lives, coins and boosters

economy.yaml sets how many lives a player holds and how long one takes to come back, the coins a player starts with and earns per new star, the out-of-moves offer and the boosters sold before a level, with their prices. Lives are an idle.Meter: the save keeps its value and refill anchor, so lives refill for the time the game was closed, and setting the device clock back grants nothing.

Layout

  • game.yaml: the project file, with the game's name, id and version, its window, the input map and the export presets.
  • levels/packs.yaml, levels/*.level.yaml: the packs and levels. data.go loads them and economy.yaml.
  • play.go: one attempt at a level: its board, the boosters applied to it, the continue offer and the stars it earns.
  • save.go: the saved progress, lives and coins.
  • game.go: the game: the loop, the input, the map, starting and ending levels, and the economy.
  • anim.go: the animation of a swap and its cascades.
  • draw.go: how the board is laid out and drawn on the Canvas.
  • ui.go: the native views: the map, the counters and buttons, and the dialogs.
  • project.go, main.go: the parsed game.yaml and the entry point.
  • *_test.go: the tests. game_test.go plays the game through nsgotest; bot_test.go wins every level with a bot; data_test.go checks the data files; play_test.go tests the rules of an attempt.
  • nsgo.yaml: NSGo app metadata and dev settings; its name, id, version and build output and targets follow game.yaml.

Git setup

Each clone enables the object-by-object scene merge driver once (.gitattributes names it, while Git keeps driver config local to .git/config):

go tool game merge -setup

Documentation

Overview

Command gemgarden is a match-3 puzzle game built with NSGo and game: swap neighboring gems to make lines of three or more, clear jelly, crates and ice, and collect colors across two packs of levels on a level map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL