游戏创意与功能

你的下一项功能

对局

使用显式修订号、不透明状态和独立结果报告的回合制游戏。

SDK:develop 分支需要玩家会话
Unity
对局功能示意图
可见的结果

使用两个玩家会话协调大厅、轮流回合和独立的最终报告。

视频稍后提供

此步骤尚无视频。指南和MCP请求已可使用。

回合制对局

准备同一个项目

  1. 在仪表盘中选择与游戏配置相同的项目。

    对局 →
  2. 首次请求不需要额外定义。没有对应游戏数据时,空结果也有效。

    使用两名玩家的独立会话:创建大厅、加入、指定顺序启动、交替提交字节状态,最后各自报告相同的最终结果。

    首个示例只读取数据,不创建群组、对局或对象。空列表也是有效的首次响应。

实现此功能

你可以预览指南。运行需要有效的项目密钥。 准备项目

已安装 SDK、导入项目配置,且玩家已登录。

此 SDK 示例使用 develop。请检查已安装的 SDK 是否具备所需 API。

先通过快速入门连接目标玩家,再通过明确的按钮或场景操作调用ReadMyMatches()。仅打开文件不会发送请求。

C#
Assets/Scripts/MatchesDemo.cs
horizOn 调用
1using UnityEngine;
2using PM.horizOn.Cloud.Manager;
3​
4public sealed class MatchesDemo : MonoBehaviour
5{
6 // Initialize/connect and restore the existing player in the Quickstart first.
7 // Invoke explicitly. The SDK also enforces the returned polling cadence.
8 public async void ReadMyMatches()
9 {
10 var user = UserManager.Instance.CurrentUser;
11 if (user == null || !user.IsValid()) return;
12 var result = await MatchesManager.Instance.GetMatches(user.UserId);
13 if (!result.IsSuccess) { Debug.LogWarning(result.ErrorCode); return; }
14 Debug.Log($"Ledger revision: {result.Data.revision}");
15 foreach (var match in result.Data.recent)
16 Debug.Log($"Match {match.id}: {match.status}");
17 // Recent may include an active match after this player's forfeit.
18 // Respect result.Data.pollAfterSeconds; no background poll or automatic timeout.
19 }
20}
21// Full two-player recipe: SDK Examples/MatchesExample and MatchesSampleStore.
22// ReadLedger/ReadMatch -> SaveCreateAfterLedgerReview/SaveActionAfterMatchReview.
23// ApplySavedIntent sends one durable original body/revision. Unknown create is reconciled.
24// Never replace a pending original with the revision from a later read.
25// ReportResult uses the original finalStateRevision/result bytes/sorted winnerIds.
26// Ordinary consensus is not trusted victory proof. Ranked runs use Validated Actions.
打开完整SDK示例 ↗

两名玩家,一个原始回合

使用两名玩家的独立会话:创建大厅、加入、指定顺序启动、交替提交字节状态,最后各自报告相同的最终结果。

发送前保存精确请求。超时后读取状态并核对。绝不悄悄替换修订号或原始意图。

报告使用不可变的最终修订号。一致并非可信胜利证明;冲突或缺失报告不会推断胜者。

排位运行需要已确认的排位对局和现有Validated Actions流程。普通对局报告不发放奖励。

PHP支持普通对局REST路由。不支持排位验证和实时功能,必要时返回FEATURE_NOT_SUPPORTED。

测试你的新功能。

使用两个玩家会话协调大厅、轮流回合和独立的最终报告。

在仪表盘中选择与游戏配置相同的项目。

接口
  • GET/matches
  • GET/matches/limits
  • GET/matches/open
  • GET/matches/{matchId}
  • POST/matches
  • POST/matches/{matchId}/join
  • POST/matches/{matchId}/decline
  • POST/matches/{matchId}/start
  • POST/matches/{matchId}/turn
  • POST/matches/{matchId}/timeout
  • POST/matches/{matchId}/leave
  • POST/matches/{matchId}/cancel
  • POST/matches/{matchId}/result
  • POST/matches/{matchId}/ranked-run
API 参考中的全部接口
下一步建议

为每一局添加最高分。

每局结束后保存分数并展示领先者。继续使用现有连接和玩家会话。