Skip to content

felinae98/SokobanASM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

icon

Core Sokoban ASM

Core logics of Sokoban Game implemented by pure and neat x86 Assembly. Main project at repo: spencerwooo/SokobanGame

俗称,推箱子。

Building

  1. 下载并安装:MASM32
  2. 使用 Visual Studio 2019 打开项目,将 Build Dependencies → Build Customization 中加入 masm 的选项
  3. 编译 sokoban.asm 时选择 x86

Usage

地图

地图为 7 行 9 列,用长度为 63 的 bytes 数组表示,对于每个点:

  • 'P' 代表人物位置
  • 'Q' 代表人站在标记位置上
  • 'B' 代表箱子位置
  • 'T' 代表箱子目标
  • 'F' 代表箱子处于完成位置
  • 'W' 代表墙
  • 'G' 代表地面
  • 'E' 不渲染

外部使用:

API 设计

函数:int result = control(char map[], int params)

map[] 代表当前地图,params 代表操作:

  • 0x00 - 0x0A 载入1-11关
  • 0x10 往上、0x11 往下、0x12 往左、0x13 往右
  • 0x20 上一步

返回值:

  • status: result >> 24
    • 0:完成
    • 1:未完成
    • 2:一步都没走呢就点上一步?
    • 3:health 用光了还想上一步?重来吧救不了
  • health: (result >> 16) & 0xff
    • 初始 5
  • step: result & 0xffff
    • 步数

注:步数和 health 每次 load 都会重置。

样例使用方法

以 C# 为例子

// Game core logics, in Assembly
[DllImport("SokobanASM.dll")]
public static extern int control(StringBuilder a, int b);

...

// Map string
StringBuilder mapString = new StringBuilder(70);

// Render map at level 1
control(mapString, 0x00);

...

// Go up
int gameResult = control(mapString, 0x10);

// Render statistics
// emmmm... See documentation for more
int currentSteps = gameResult & 0xffff;
int currentHealth = (gameResult & 0xff0000) >> 16;
int currentStatus = gameResult >> 24;

🎮 Sokoban Game ©2019 Team Offline Flower. Released under the MIT License.

Authored and maintained by @Felinae Tang with help from @Spencer Woo, @Garvey Lau and @Liz Li. Team Offline Flower, all rights reserved.

@Blog · @GitHub

About

asm part of sokoban

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published