From 203d7958f7a7b02dd5e80adb338d558f6b04764d Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 11 Jul 2018 22:42:08 +0800 Subject: [PATCH] update server to 1.0.4 --- api/GetGame_CN.md | 10 +++++++++- src/server/MagCore.Core/Game.cs | 17 ++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/GetGame_CN.md b/api/GetGame_CN.md index 4986125..259109c 100644 --- a/api/GetGame_CN.md +++ b/api/GetGame_CN.md @@ -17,7 +17,14 @@ Content: "Id": "ce71d669e4d141a298472591de92f8e6", "Map": "RectSmall", "State": 0, - "Players": [], + "Players": [ + { + "Index": 5, + "Color": 1, + "Name": "cc", + "State": 1 + } + ], "Cells": [ [{ "X": 0, @@ -63,6 +70,7 @@ Players: 当前游戏中的玩家**数组** - Index: 玩家的标识号 - Color: 玩家的颜色 - Name: 玩家昵称 + - State: 玩家状态 Cells: 游戏所有单元的状态**二维数组** - X: 单元的x坐标 diff --git a/src/server/MagCore.Core/Game.cs b/src/server/MagCore.Core/Game.cs index dd44fee..852ead2 100644 --- a/src/server/MagCore.Core/Game.cs +++ b/src/server/MagCore.Core/Game.cs @@ -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); @@ -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) { @@ -89,6 +84,10 @@ public Game(IMap map) break; } } + else + { + Thread.Sleep(100); + } ProcessVictory(); }