public SquareSitResponse Sit(SquareSitRequest request) { var res = new SquareSitResponse(); //var userID = Utils.GetUserIDByToken(request.Token); //var square = chessContext.Squares[userID]; var tableId = Utils.GetRequestParam <int>(request.Biz_Content, "table_id"); var table = ChessingManager.Instance.Tables[tableId]; ISquare square = Square; if (square != null) { if (square.Table != null && square.Table != table) { throw new Exception(string.Format("Error when user {0} Sit at table {1}, square with other table ", UserID, tableId)); } } else { var newCamp = !table.Squares.Keys.Contains(Camp.RedCamp) ? Camp.RedCamp : Camp.BlackCamp; square = new Square(newCamp, newCamp == Camp.RedCamp ? ChessColor.Red : ChessColor.Black); ChessingManager.Instance.Squares.Add(UserID, square); } square.Sit(table); return(res); }
static void Demo() { var serverUrl = "http://localhost:28310/"; IClient client = new DefaultClient(serverUrl, null, null); var sitReq = new SquareSitRequest() { Biz_Content = Newtonsoft.Json.JsonConvert.SerializeObject(new Dictionary <string, string>() { { "table_id", "1" } }) }; var sitRes = client.Execute(sitReq, "1"); var readyReq = new SquareReadyRequest(); var readyRes = client.Execute(readyReq); var moveReq1 = new ChessMoveRequest() { Biz_Content = Newtonsoft.Json.JsonConvert.SerializeObject(new Dictionary <string, string>() { { "chesstype", ChessType.Cannons.ToString().ToLower() }, { "index", "0" }, { "relativex", "4" }, { "relativey", "2" }, }) }; var moveRes1 = client.Execute(moveReq1); //stories //tom and jerry sit at board 1 //tom ready //jerry ready //board start //var red = new Square("tom"); //var black = new Square("jerry"); //var table = new Table(); //var ing = new Chessing("tom vs jerry at 2018.6.20 17:40"); //table.StartChessing(ing); //ing.Start(true);//at red }
public SquareSitResponse Sit(SquareSitRequest request) { return(Utils.TryGetResponse(request, service.Sit, UserID)); }