public JsonResult getCurrentFlightChartData() { try { string DroneName; List <object> iData = new List <object>(); List <string> labels = new List <string>(); List <string> labelsShort = new List <string>(); List <double> lst_dataItem_2 = new List <double>(); List <double> lst_dataItem_1 = new List <double>(); List <double> lst_dataItem_3 = new List <double>(); List <double> lst_dataItem_4 = new List <double>(); List <double> lst_dataItem_5 = new List <double>(); IList <ChartViewModel> ChartList = Util.getCurrentFlightChartData(); foreach (ChartViewModel FMD in ChartList) { //labels.Add(FMD.DroneName); DroneName = FMD.DroneName; labels.Add(FMD.DroneName); labelsShort.Add(DroneName.Split('-').Last()); lst_dataItem_1.Add(Math.Round((FMD.TotalFightTime / 60), 2)); lst_dataItem_2.Add(Math.Round((FMD.CurrentFlightTime / 60), 2)); lst_dataItem_3.Add(Math.Round((FMD.LastFlightTime / 60), 2)); } iData.Add(labels); iData.Add(lst_dataItem_1); iData.Add(lst_dataItem_2); iData.Add(labelsShort); iData.Add(lst_dataItem_3); //iData.Add(lst_dataItem_3); //iData.Add(lst_dataItem_4); //iData.Add(lst_dataItem_5); return(Json(iData, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { if (DebugOption == "True") { throw ex; } else { return(null); } } }
void ChangeDronePosition(DroneName droneName, Direction direction) { if (!GetAllowedMoves(this.dronePositions[droneName], false).Contains(direction)) { return; } UpdateDotColor(this.dronePositions[droneName], Color.white); UpdateDotText(this.dronePositions[droneName], ""); this.dronePositions[droneName] = GetMoveDestination(this.dronePositions[droneName], direction); UpdateDotText(this.dronePositions[droneName], droneName.ToString()); UpdateDotColor(this.dronePositions[droneName], Color.clear); EvaluateCollisions(); this.bomberRunning = true; }
// This example requires the System and System.Net namespaces. public void SimpleListenerExample(string[] prefixes) { // Create a listener. HttpListener listener = new HttpListener(); // Add the prefixes. foreach (string s in prefixes) { listener.Prefixes.Add(s); } listener.Start(); while (true) { // Note: The GetContext method blocks while waiting for a request. HttpListenerContext context = listener.GetContext(); HttpListenerRequest request = context.Request; // Obtain a response object. HttpListenerResponse response = context.Response; // Construct a response. string responseString = ""; if (gameActive && !request.Url.OriginalString.Contains("favicon")) { responseString += "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"></head><body>"; Dictionary <string, string> queryStrings = new Dictionary <string, string>(); string query = request.Url.Query; if (query.Length > 1) { // Leading '?' query = query.Substring(1); } foreach (string fullQueryString in query.Split('&')) { string[] split = fullQueryString.Split('='); if (split.Length != 2) { continue; } queryStrings.Add(split[0], split[1]); } if (this.connectionTextColor != Color.green) { this.connectionTextColor = Color.green; actions.Enqueue(delegate() { this.connectionText.color = Color.green; }); } DroneName selectedDrone = DroneName.A; string drone; if (queryStrings.TryGetValue("drone", out drone)) { drone = drone.ToUpperInvariant(); foreach (DroneName possibleDrone in Enum.GetValues(typeof(DroneName))) { if (possibleDrone.ToString() == drone) { selectedDrone = possibleDrone; break; } } } string attemptNumString; string move = null; string jam = null; if (queryStrings.TryGetValue("attempt", out attemptNumString) && this.attemptNumber.ToString() == attemptNumString) { if (queryStrings.TryGetValue("move", out move)) { foreach (Direction possibleDirection in Enum.GetValues(typeof(Direction))) { if (string.Equals(move, possibleDirection.ToString(), StringComparison.OrdinalIgnoreCase)) { actions.Enqueue(delegate() { ChangeDronePosition(selectedDrone, possibleDirection); }); break; } } } else if (queryStrings.TryGetValue("jam", out jam)) { foreach (JamType possibleJamType in JamTypes.All()) { if (string.Equals(jam, possibleJamType.DisplayName, StringComparison.OrdinalIgnoreCase)) { actions.Enqueue(delegate() { Jam(possibleJamType); }); break; } } } } responseString += "<b>Selected Drone:</b> " + selectedDrone.ToString() + " " + "<b>Last Move:</b> " + (move != null && move.Count() > 0 ? move : "(no move)") + " " + "<br/><b>Jam Fired?:</b> " + (jam != null && jam.Count() > 0 ? jam : "(no jam)") + "<br/><br/><br/>"; responseString += "<table><tr><th colspan=\"4\"><b>Drones</b></th></tr><tr>"; foreach (DroneName droneName in Enum.GetValues(typeof(DroneName))) { responseString += "<td> <a href=\"?attempt=" + this.attemptNumber + "&drone=" + droneName.ToString() + "\">" + droneName.ToString() + "</a> <br/></td>"; } responseString += "</tr></table>"; responseString += "<br/><b>Controls:</b><br/>"; responseString += "<table>"; responseString += "<tr><td></td><td>"; responseString += "<center> <a href=\"?attempt=" + this.attemptNumber + "&drone=" + selectedDrone.ToString() + "&move=" + Direction.Up.ToString() + "\">" + Direction.Up.ToString() + "</a> </center><br/>"; responseString += "</td><td></td></tr>"; responseString += "<tr>"; responseString += "<td>"; responseString += "<center> <a href=\"?attempt=" + this.attemptNumber + "&drone=" + selectedDrone.ToString() + "&move=" + Direction.Left.ToString() + "\">" + Direction.Left.ToString() + "</a> </center><br/>"; responseString += "</td>"; responseString += "<td>"; responseString += "</td>"; responseString += "<td>"; responseString += "<center> <a href=\"?attempt=" + this.attemptNumber + "&drone=" + selectedDrone.ToString() + "&move=" + Direction.Right.ToString() + "\">" + Direction.Right.ToString() + "</a> </center><br/>"; responseString += "</td>"; responseString += "</td><td></td></tr>"; responseString += "<tr><td></td><td>"; responseString += "<center> <a href=\"?attempt=" + this.attemptNumber + "&drone=" + selectedDrone.ToString() + "&move=" + Direction.Down.ToString() + "\">" + Direction.Down.ToString() + "</a> </center><br/>"; responseString += "</td><td></td></tr>"; responseString += "</table>"; responseString += "<table><tr><th colspan=\"4\"><b>Fire Jammer!</b></th></tr><tr>"; foreach (JamType jamType in JamTypes.All()) { responseString += "<td> <a href=\"?attempt=" + this.attemptNumber + "&jam=" + jamType.DisplayName + "\">" + jamType.DisplayName + "</a> <br/></td>"; } responseString += "</tr></table>"; responseString += "</body></html>"; } byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); } }