fc01/TypeGame
About
👾 Sokoban Game in Pure TypeScript Type System
Games & EmulationMeasured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
readme.en.md
OriginalTypeSokoban
This is a "Sokoban" game implemented entirely within the TypeScript type system. It contains no runtime JavaScript logic; all game logic, map rendering, and win/loss conditions are processed during the compilation phase via type checking.
Symbol Descriptions
| Symbol | Meaning |
|---|---|
👾 |
Player |
👽 |
Player on Target |
😃 |
Box |
😎 |
Box on Target |
🕶️ |
Target |
🎇 |
Wall |
🌑 |
Floor |
How to Play
The game is played using TypeScript property access (Dot Notation). In src/index.ts, you can control the player's movement through a sequence of dots:
- Select Level: Use
.stage1through.stage100. - Controls:
.w: Move Up.s: Move Down.a: Move Left.d: Move Right
- View Map: Append
.overafter your movement commands. Your IDE's type hint (Hover) will display the rendered string of the current map. - Victory Condition: Once all boxes are pushed onto targets (i.e., the
😃symbol is no longer present in the map), the type system grants access to.GameClear.WoW.MuchFun.
Example
TypeGame
.stage1 // Enter Level 1
.s.d.d.over // Move Down once, Right twice, then view the map
Core Implementation Principles
1. State Machine (src/TypeGame.ts)
The core logic is encapsulated in the Step type. It determines what a cell should become in the next turn based on its current type and the states of the two cells ahead and behind it in the direction of movement (prev2, prev1, next1, next2).
2. Coordinate Transformation (src/utils.ts)
To simplify the logic, the system only implements the logic for "Move Left". For Up, Down, and Right movements, the system uses the MatrixRotateAndScale type to rotate/transpose the 2D array (matrix), converting the problem into a "Move Left" scenario, and then rotates it back.
3. Recursive Rendering (src/utils.ts)
Join: Concatenates a tuple of symbols into a single long string.Render: Converts the 2D array into a nested object structure, allowing the IDE's type preview to display the map as a multi-line string.
Development Environment
- VSCode is recommended.
- Ensure TypeScript version is 4.1 or higher (supporting Template Literal Types).
- Hover over the
.overproperty insrc/index.tsto see the real-time rendered game screen.
Explore related projects
Loading…