Ejemplo n.º 1
0
        public IActionResult Board([FromQuery] string gameId, [FromQuery] string color)
        {
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            System.Threading.Semaphore s = new System.Threading.Semaphore(1, 1, "COPS"); s.WaitOne();
            try
            {
                if (null == gameId || color == null)
                {
                    return(BadRequest());
                }
                MakeCertainGameExists(gameId);
                var board = VisualBoardStore.GameBoard(gameId);
                var hues  = VisualBoardStore.TeamHues(gameId, color);
                //            var hues = VisualBoardStore.ReplaceHues(gameid, color);

                string json = "[";

                foreach (var spot in board)
                {
                    json += "{\"loc\":\"" + spot.Key;
                    json += "\",\"tok\":\"" + spot.Value;

                    string hue = "128,128,128,0.9";
                    if (spot.Key == "n0_n0")
                    {
                        hue = "0,0,0,1.0";
                    }

                    if (hues.ContainsKey(spot.Key))
                    {
                        hue = hues[spot.Key];
                    }



                    json += "\",\"hue\":\"" + hue;

                    json += "\"},";
                }

                json  = json.Substring(0, json.Length - 1);
                json += "]";

                return(Ok(json));
            }
            finally { s.Release(); }
        }