Skip to content

Commit

Permalink
update server to 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvees committed Jul 11, 2018
1 parent 8b96b0e commit 203d795
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 9 additions & 1 deletion api/GetGame_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ Content:
"Id": "ce71d669e4d141a298472591de92f8e6",
"Map": "RectSmall",
"State": 0,
"Players": [],
"Players": [
{
"Index": 5,
"Color": 1,
"Name": "cc",
"State": 1
}
],
"Cells": [
[{
"X": 0,
Expand Down Expand Up @@ -63,6 +70,7 @@ Players: 当前游戏中的玩家**数组**
- Index: 玩家的标识号
- Color: 玩家的颜色
- Name: 玩家昵称
- State: 玩家状态

Cells: 游戏所有单元的状态**二维数组**
- X: 单元的x坐标
Expand Down
17 changes: 8 additions & 9 deletions src/server/MagCore.Core/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public string ToJson()
foreach (Player player in Players.Values)
{
//sPlayers.Add("\"" + player.Index + "\"");
string single = "{{\"Index\":{0}, \"Color\":{1}, \"Name\":\"{2}\"}}";
single = string.Format(single, player.Index, (int)player.Color, player.Name);
string single = "{{\"Index\":{0}, \"Color\":{1}, \"Name\":\"{2}\", \"State\":{3}}}";
single = string.Format(single, player.Index, (int)player.Color, player.Name, (int)player.State);
sPlayers.Add(single);
}
players = string.Join(",", sPlayers);
Expand Down Expand Up @@ -71,14 +71,9 @@ public Game(IMap map)
}
try
{
while (_state != GameState.Done)
while (_state == GameState.Playing)
{
if (_commands.IsEmpty || _state != GameState.Playing)
{
Thread.Sleep(100);
continue;
}
else if (_commands.TryDequeue(out var cmd))
if (!_commands.IsEmpty && _commands.TryDequeue(out var cmd))
{
switch (cmd.Action)
{
Expand All @@ -89,6 +84,10 @@ public Game(IMap map)
break;
}
}
else
{
Thread.Sleep(100);
}
ProcessVictory();
}
Expand Down

0 comments on commit 203d795

Please sign in to comment.