@zktcg/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.43 • Public • Published

ZKTCG Frontend

Data types

GameInfo: 和之前的 BoardInfo 一样,包含了所有的数据

zk

// 和之前一样
await decryptCard(cardIndex: number);

Init SDK

/** tokenIds 是 card config 的 id 集合,比如 card config 是
[
    {id: 1001, name: xxx, type: xxx },
    {id: 1002, name: xxx, type: xxx },
    {id: 1003, name: xxx, type: xxx },
]
这里就传入 [1001, 1002, 1003] 
**/
const sdk = new TCGSDK({
    signer, provider,
    tokenIds,
});

// 初始化
await sdk.init();

SDK interfaces

// 和之前一样的接口
await sdk.loadResources();

await sdk.estimateTotalRequireGasForOneGame();

await sdk.authorizeGameAccount();

await sdk.getGameAccountBalance();

await sdk.getGameAccountAddress();

await sdk.checkRequireGas(gameCount: number);

await sdk.fundGameAccount(gameCount: number, force: boolean);

await sdk.withdrawGameAccount();

await sdk.getGameInstance(gameId: number);

await sdk.getL1GasPrice();

await sdk.getAccountInfo(address: string);


// heroType: 选择的英雄种类
// 和之前一样会返回 stateMachine
await sdk.createGame(heroType);

Game instance interfaces

获取game instance

const game = await sdk.getGameInstance(gameId);
// 监听接口,和之前 onBoardUpdate 一样
game.onGameInfoUpdate((newGameInfo: GameInfo) => {
    ....
})

// 加入游戏
await game.joinGame(buyinAmount: number, heroType: HeroType);

// 加入游戏后,需要双方调用 prepare 得到起手牌,底层是双方都 deal 对方的起手牌
await game.prepare();

// 第一次 shuffle,双方轮流做
await game.firstShuffleDeck();

// 第一次 shuffle,双方轮流做
await game.secondShuffleDeck();

// 本round结束,轮到对手出牌
await game.nextRound();

// 帮对手发牌,只有在法术牌某些效果生效的时候才会直接调用
await game.drawCard();

// 对手超时后踢掉对方
await game.kickPlayer();

// 投降
await game.surrender();

// 使用英雄效果
await game.useHeroEffects();

// 使用英雄攻击,targetIdx 为 99 的时候攻击对方英雄
// targetIdx 为其他值的时候攻击对方 随从, 可以从
// gameInfo 中拿到对方 随从 然后挑选
await game.useHeroAttack(targetIdx: number);

// 使用随从攻击,minionIdx 为挑选的随从,targetIdx 规则同上
await game.useMinionAttack(
    minionIdx: number,
    targetIdx: number,
);

// 和之前一样
await game.playerIndex();

Game flow

初始化

和 holdem 一样,初始化sdk,下载资源,setup account, ...

游戏流程

  • 房主(creator) sdk.createGame
  • 对手(joiner) sdk.joinGame,加入后游戏自动开始
  • creator 和 joiner 轮流调用 sdk.prepare
  • creator 和 joiner 轮流调用 sdk.firstShuffleDeck
  • creator 和 joiner 轮流调用 sdk.secondShuffleDeck
  • 进入 play 阶段,creator 调用 game.nextRound, 轮到 joiner 出牌
    • joiner 调用 game.playCard(cardIndex), cardIndex 就是 handCards
    • joiner 可以多次调用 playCard, useHeroAttack, usexxx 等,直到 currentMana 用完
    • joiner 点击 game.nextRound,切换到 creator
    • creator 重复上面步骤
    • ...

Readme

Keywords

none

Package Sidebar

Install

npm i @zktcg/sdk

Weekly Downloads

0

Version

0.0.43

License

none

Unpacked Size

7.03 MB

Total Files

28

Last publish

Collaborators

  • naivecoder