Skip to content

Commit 203d795

Browse files
committed
update server to 1.0.4
1 parent 8b96b0e commit 203d795

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

api/GetGame_CN.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ Content:
1717
"Id": "ce71d669e4d141a298472591de92f8e6",
1818
"Map": "RectSmall",
1919
"State": 0,
20-
"Players": [],
20+
"Players": [
21+
{
22+
"Index": 5,
23+
"Color": 1,
24+
"Name": "cc",
25+
"State": 1
26+
}
27+
],
2128
"Cells": [
2229
[{
2330
"X": 0,
@@ -63,6 +70,7 @@ Players: 当前游戏中的玩家**数组**
6370
- Index: 玩家的标识号
6471
- Color: 玩家的颜色
6572
- Name: 玩家昵称
73+
- State: 玩家状态
6674

6775
Cells: 游戏所有单元的状态**二维数组**
6876
- X: 单元的x坐标

src/server/MagCore.Core/Game.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public string ToJson()
3939
foreach (Player player in Players.Values)
4040
{
4141
//sPlayers.Add("\"" + player.Index + "\"");
42-
string single = "{{\"Index\":{0}, \"Color\":{1}, \"Name\":\"{2}\"}}";
43-
single = string.Format(single, player.Index, (int)player.Color, player.Name);
42+
string single = "{{\"Index\":{0}, \"Color\":{1}, \"Name\":\"{2}\", \"State\":{3}}}";
43+
single = string.Format(single, player.Index, (int)player.Color, player.Name, (int)player.State);
4444
sPlayers.Add(single);
4545
}
4646
players = string.Join(",", sPlayers);
@@ -71,14 +71,9 @@ public Game(IMap map)
7171
}
7272
try
7373
{
74-
while (_state != GameState.Done)
74+
while (_state == GameState.Playing)
7575
{
76-
if (_commands.IsEmpty || _state != GameState.Playing)
77-
{
78-
Thread.Sleep(100);
79-
continue;
80-
}
81-
else if (_commands.TryDequeue(out var cmd))
76+
if (!_commands.IsEmpty && _commands.TryDequeue(out var cmd))
8277
{
8378
switch (cmd.Action)
8479
{
@@ -89,6 +84,10 @@ public Game(IMap map)
8984
break;
9085
}
9186
}
87+
else
88+
{
89+
Thread.Sleep(100);
90+
}
9291

9392
ProcessVictory();
9493
}

0 commit comments

Comments
 (0)