|
| 1 | +# Client 调试客户端使用指南 |
| 2 | + |
| 3 | +## 1. 启动 Server |
| 4 | +可使用命令行或 Visual Studio 启动 Server,启动后会监听本地 8888 端口。 |
| 5 | +相关命令行参数如下所示,可在 `\THUAI7\logic\Server\ArgumentOptions.cs` 中查看。 |
| 6 | + |
| 7 | +```Csharp |
| 8 | +public class ArgumentOptions |
| 9 | +{ |
| 10 | + [Option("ip", Required = false, HelpText = "Server listening ip")] |
| 11 | + public string ServerIP { get; set; } = "localhost"; |
| 12 | + |
| 13 | + [Option('p', "port", Required = true, HelpText = "Server listening port")] |
| 14 | + public ushort ServerPort { get; set; } = 8888; |
| 15 | + |
| 16 | + [Option("teamCount", Required = false, HelpText = "The number of teams, 2 by defualt")] |
| 17 | + public ushort TeamCount { get; set; } = 2; |
| 18 | + |
| 19 | + [Option("shipNum", Required = false, HelpText = "The max number of Ship, 4 by default")] |
| 20 | + public ushort ShipCount { get; set; } = 4; |
| 21 | + |
| 22 | + [Option("homeNum", Required = false, HelpText = "The number of Home , 1 by default")] |
| 23 | + public ushort HomeCount { get; set; } = 1; |
| 24 | + |
| 25 | + [Option('g', "gameTimeInSecond", Required = false, HelpText = "The time of the game in second, 10 minutes by default")] |
| 26 | + public uint GameTimeInSecond { get; set; } = 10 * 60; |
| 27 | + [Option('f', "fileName", Required = false, HelpText = "The file to store playback file or to read file.")] |
| 28 | + public string FileName { get; set; } = "114514"; |
| 29 | + [Option("notAllowSpectator", Required = false, HelpText = "Whether to allow a spectator to watch the game.")] |
| 30 | + public bool NotAllowSpectator { get; set; } = false; |
| 31 | + [Option('b', "playback", Required = false, HelpText = "Whether open the server in a playback mode.")] |
| 32 | + public bool Playback { get; set; } = false; |
| 33 | + [Option("playbackSpeed", Required = false, HelpText = "The speed of the playback, between 0.25 and 4.0")] |
| 34 | + public double PlaybackSpeed { get; set; } = 1.0; |
| 35 | + [Option("resultOnly", Required = false, HelpText = "In playback mode to get the result directly")] |
| 36 | + public bool ResultOnly { get; set; } = false; |
| 37 | + [Option('k', "token", Required = false, HelpText = "Web API Token")] |
| 38 | + public string Token { get; set; } = "114514"; |
| 39 | + [Option('u', "url", Required = false, HelpText = "Web Url")] |
| 40 | + public string Url { get; set; } = "114514"; |
| 41 | + [Option('m', "mapResource", Required = false, HelpText = "Map Resource Path")] |
| 42 | + public string MapResource { get; set; } = DefaultArgumentOptions.MapResource; |
| 43 | + [Option("requestOnly", Required = false, HelpText = "Only send web requests")] |
| 44 | + public bool RequestOnly { get; set; } = false; |
| 45 | + [Option("finalGame", Required = false, HelpText = "Whether it is the final game")] |
| 46 | + public bool FinalGame { get; set; } = false; |
| 47 | + [Option("cheatMode", Required = false, HelpText = "Whether to open the cheat code")] |
| 48 | + public bool CheatMode { get; set; } = false; |
| 49 | + [Option("resultFileName", Required = false, HelpText = "Result file name, saved as .json")] |
| 50 | + public string ResultFileName { get; set; } = "114514"; |
| 51 | + [Option("startLockFile", Required = false, HelpText = "Whether to create a file that identifies whether the game has started")] |
| 52 | + public string StartLockFile { get; set; } = "114514"; |
| 53 | + [Option("mode", Required = false, HelpText = "Whether to run final competition")] |
| 54 | + public int Mode { get; set; } = 0; |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +其中,主要需要改动的是 `TeamCount` , `ShipCount` 和 `HomeCount` ,分别代表队伍总数量,每队船只总数量和基地总数量。只有加入的 Client 对应数据满足这些条件,Server 才能开始游戏并发送数据。 |
| 59 | +进行游戏的最小条件是有一支队伍(默认红队)与一个基地,即设置 `TeamCount` 为 1, `ShipCount` 为 0, `HomeCount` 为 1 。只有加入了基地才能加入船只。如果需要测试船只,则最小条件为 `TeamCount` 为 1, `ShipCount` 为 1, `HomeCount` 为 1 。 |
| 60 | + |
| 61 | +## 2. 启动 Client |
| 62 | +目前 Client 只能通过 Visual Studio 启动,其与 Server 的连接函数位于 `\THUAI7\logic\Client\ViewModel\GeneralViewModel.cs` 中的 `ConnectToServer` 函数中,如下所示。 |
| 63 | + |
| 64 | +```Csharp |
| 65 | +// 连接Server,comInfo[]的格式:0-ip 1- port 2-playerID 3-teamID 4-ShipType |
| 66 | +ConnectToServer(new string[]{ |
| 67 | + "localhost", |
| 68 | + "8888", |
| 69 | + "0", |
| 70 | + "0", |
| 71 | + "1" |
| 72 | +}); |
| 73 | +``` |
| 74 | + |
| 75 | +其中,传入参数对应的含义已在上方标明。修改对应的参数并运行 Client ,即可按照所加参数连接 Server 并添加相关的 player 信息。 |
| 76 | + |
| 77 | +## 3. 启动游戏 |
| 78 | +如果希望启动游戏,则需进行以下步骤: |
| 79 | + |
| 80 | +1. 按照对应的参数启动 Server 。 |
| 81 | +2. 如果 Server 中设置 `TeamCount` 为 1, `ShipCount` 为 0, `HomeCount` 为 1 ,则可以直接启动 Client ,即可看到游戏开始。 |
| 82 | +3. 如果 Server 中的参数要求有更多的 Client 加入,则需要依次启动相应参数的 Client ,直到满足 Server 的条件。由于 Server 只要求有 Client 加入,而无需对应 Client 进程保持运行,可在加入一个 Client 后关闭其进程,再启动下一个 Client 。 |
| 83 | + 例如,如果希望加入一支队伍,这支队伍有一只船只,则可以按照如下步骤启动: |
| 84 | + 1. Server 设置 `TeamCount` 为 1, `ShipCount` 为 1, `HomeCount` 为 1 。 |
| 85 | + 2. 启动一个 Client ,设置 `playerID` 为 0,`teamID` 为 0, `ShipType` 为 1 ,即加入一个 `home`。 |
| 86 | + 3. 关闭该 Client 进程,再重新启动一个 Client ,设置 `playerID` 为 1,`teamID` 为 0, `ShipType` 为 1 ,即加入一个 `ship`。 |
| 87 | +此时即可看到游戏开始。 |
0 commit comments