internal void Init(string CapabilitiesString, WFSDataset wfsDataset) { try { _themes = new List <IWebServiceTheme>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(CapabilitiesString); XmlNode CapabilitiesNode = doc.SelectSingleNode("WMT_MS_Capabilities/Capability"); _getCapabilities = new GetCapabilities(CapabilitiesNode.SelectSingleNode("Request/GetCapabilities")); _getMap = new GetMap(CapabilitiesNode.SelectSingleNode("Request/GetMap")); _getFeatureInfo = new GetFeatureInfo(CapabilitiesNode.SelectSingleNode("Request/GetFeatureInfo")); _describeLayer = new DescribeLayer(CapabilitiesNode.SelectSingleNode("Request/DescribeLayer")); _getLegendGraphic = new GetLegendGraphic(CapabilitiesNode.SelectSingleNode("Request/GetLegendGraphic")); _getStyles = new GetStyles(CapabilitiesNode.SelectSingleNode("Request/GetStyles")); _exceptions = new WMSExceptions(CapabilitiesNode.SelectSingleNode("Exception")); _userDefinedSymbolization = new UserDefinedSymbolization(CapabilitiesNode.SelectSingleNode("UserDefinedSymbolization")); XmlNode service = CapabilitiesNode.SelectSingleNode("Layer"); XmlNode title = service.SelectSingleNode("Title"); if (title != null) { _name = title.InnerText; } _srs = new SRS(service); this.SRSCode = _srs.Srs[_srs.SRSIndex]; foreach (XmlNode layer in service.SelectNodes("Layer")) { string name = "", Title = ""; XmlNode nameNode = layer.SelectSingleNode("Name"); XmlNode titleNode = layer.SelectSingleNode("Title"); if (nameNode == null) { continue; } name = Title = nameNode.InnerText; if (titleNode != null) { Title = titleNode.InnerText; } XmlNodeList styles = layer.SelectNodes("Style"); WFSFeatureClass wfsFc = null; if (wfsDataset != null) { IDatasetElement wfsElement = wfsDataset[name]; if (wfsElement != null && wfsElement.Class is WFSFeatureClass) { wfsFc = wfsElement.Class as WFSFeatureClass; } } if (styles.Count == 0) { IClass wClass = null; if (wfsFc != null) { wClass = wfsFc; } else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1") { wClass = new WMSQueryableThemeClass(_dataset, name, String.Empty, layer, _getFeatureInfo, _srs, _exceptions); } else { wClass = new WMSThemeClass(_dataset, name, String.Empty, layer); } IWebServiceTheme theme; if (wClass is WFSFeatureClass) { theme = new WebServiceTheme2( wClass, Title, name, true, this); } else { theme = new WebServiceTheme( wClass, Title, name, true, this ); } _themes.Add(theme); } else { foreach (XmlNode style in styles) { string sName = "", sTitle = ""; XmlNode sNameNode = style.SelectSingleNode("Name"); XmlNode sTitleNode = style.SelectSingleNode("Title"); if (sNameNode == null) { continue; } sName = sTitle = sNameNode.InnerText; if (sTitleNode != null) { sTitle = sTitleNode.InnerText; } IClass wClass = null; if (wfsFc is WFSFeatureClass) { wClass = wfsFc; ((WFSFeatureClass)wClass).Style = sName; } else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1") { wClass = new WMSQueryableThemeClass(_dataset, name, sName, layer, _getFeatureInfo, _srs, _exceptions); } else { wClass = new WMSThemeClass(_dataset, name, sName, layer); } IWebServiceTheme theme; if (wClass is WFSFeatureClass) { theme = new WebServiceTheme2( wClass, Title + " (Style=" + sTitle + ")", name, true, this); } else { theme = new WebServiceTheme( wClass, Title + " (Style=" + sTitle + ")", name, true, this ); } _themes.Add(theme); } } } doc = null; } catch (Exception ex) { string errMsg = ex.Message; } }
void MenuControl(string item) { string info; switch (item.ToLower().Substring(0, 3)) { case "tar": // calculate torpedo course info = Course.Calculation("Torpedo Course Calculation", 10, SRS.GetMyRow(), SRS.GetMyCol()); if (info != null) { ComsChatter("Computer returned " + info); } break; case "war": // calculate warp course info = Course.Calculation("Ship Course Calculation", GameBoard.GetSize(), GameBoard.getMyLocation() / GameBoard.GetSize(), GameBoard.getMyLocation() % GameBoard.GetSize()); if (info != null) { ComsChatter("Computer returned " + info); } break; case "lau": // launch probe to sector Probes.Execute(); break; case "new": // new game if (Dialogs.YesNoDialog("New Game", "Do you wish to start a new game?") == System.Windows.Forms.DialogResult.Yes) { NewGame(8); } break; case "qui": // quit if (Dialogs.YesNoDialog("Exit Game", "Do you wish to quit?") == System.Windows.Forms.DialogResult.Yes) { Debug("User exited through menu - normal exit"); System.Windows.Forms.Application.ExitThread(); this.Close(); } break; case "ins": // instructions info = "Instructions.txt was not found"; try { info = File.ReadAllText(@"Instructions.html"); info = info.Replace("{K}", GameBoard.getKlingonCount().ToString()); } catch (Exception) { // don't do anything } Dialogs.OKDialog("Instructions", info); break; case "abo": // about info = "<html><H1><i>STAR TREK</i></H1><br>" + "Released freely to the public domain.<br><br>" + "A modern version styled after the 1970's console based game " + "developed by Mike Mayfield and recreated, largely from memory, by Jon Walker.<br><br>" + "The purpose of this game is to help others learn basic C# coding by example. " + "All of the concepts here are very straight forward and will be building blocks " + "for many WPF projects.<br><br>" + "Written using Visual Studio Community 2019<br><html>"; Dialogs.OKDialog("About", info); break; case "cre": // credits info = "<html><H1>References</H1>" + "Wikipedia<br> <u>en.wikipedia.org/wiki/Star_Trek_(1971_video_game)</u><br><br>" + "Bob's Games<br> <u>www.bobsoremweb.com/startrek.html</u><br><br>" + "Tom Almy's Super StarTrek<br> <u>www.almy.us/sst.html</u><br><br><br>" + "StackOverflow<br> <u>www.stackoverflow.com</u></html>"; Dialogs.OKDialog("About", info); break; } }
/* * Button execution was broken out of the button handler so the * short cut keys can access it in a straight forward way */ private void ButtonCommand(string btn) { bool executed = false; // prevent button hot keys during timer execution if (timerStep == 0) { Debug(btn + " pressed"); switch (btn.ToUpper()) { case "IMPL": executed = Impulse.Execute(); break; case "WARP": executed = Warp.Execute(); if (executed) { SRS.Execute(); } break; case "SHLD": Shields.Execute(); timerStep = 4; timer.Enabled = true; //SetCondition(); break; case "POWER": Shields.divertPower(); timerStep = 4; timer.Enabled = true; //SetCondition(); break; case "TORP": executed = Torpedoes.Execute(); break; case "PHAS": executed = Phasers.Execute(); break; case "DMG": DamageControl.FixAllDamage(); timerStep = 4; timer.Enabled = true; //SetCondition(); break; } if (executed) { // update status before animation starts SetCondition(); if (IsUsingAnimation()) { timerStep = 1; timer.Enabled = true; } else { Debug("No Animation Executing"); GameObjects.MoveWithNoAnimation(); GameObjects.TakingFire(); GameObjects.MoveWithNoAnimation(); } } } }
private void SetConditionExecute() { WriteToLog.write("SetCondition - starDate=" + GameBoard.CurrentStarDate() + " energy=" + this.energyLevel); // set the alert level if (GameBoard.GetGameBoard() % 100 / 10 > 0) { this.alertLevel = REDALERT; } else { //energy <15% or or shields up is yellow alert if (this.energyLevel < 15 || Shields.AreUp()) { this.alertLevel = YELLOWALERT; } else { this.alertLevel = GREENALERT; } } Debug("Alert Level = " + alertLevel); // update the form this.Dispatcher.BeginInvoke((Action)(() => { Debug("Updating Status"); switch (this.alertLevel) { case REDALERT: lblAlert.Content = "RED"; break; case YELLOWALERT: this.lblAlert.Content = "YELLOW"; break; default: this.lblAlert.Content = "GREEN"; break; } // update labels - the updatecontent method sends // the info to the log file when in debug mode UpdateContent(lblStarDate, String.Format("{0:0.0} ({1:0.0})", this.GameBoard.CurrentStarDate(), GameBoard.TimeLeft())); UpdateContent(lblEnergy, String.Format("{0:0.0}%", this.energyLevel)); UpdateContent(lblKlingons, GameBoard.getKlingonCount().ToString()); lblImpulse.Content = Impulse.HealthPercent() + "%"; lblWarp.Content = Warp.HealthPercent() + "%"; lblPhasers.Content = Phasers.HealthPercent() + "%"; lblTorpedoes.Content = Torpedoes.HealthPercent() + "%"; lblTorpedoCount.Content = "(" + Torpedoes.getCurrentCount() + " Remaining)"; lblShields.Content = Shields.HealthPercent() + "%"; lblLRS.Content = LRS.HealthPercent() + "%"; lblShieldPowerRemaining.Content = Shields.levelPercent() + "%"; string[] loc = GameBoard.GetLocationInfo(); lblQuadrant.Content = loc[0]; lblSector.Content = loc[1]; })); // set button colors Debug("Set buttons"); this.Dispatcher.BeginInvoke((Action)(() => { // update button background btnImpulse.Background = ((Impulse.IsHealthy() ? LTGREEN : REDISH)); btnWarp.Background = ((Warp.IsHealthy() ? LTGREEN : REDISH)); btnTorpedoes.Background = ((Torpedoes.IsHealthy() ? (Torpedoes.getCurrentCount() > 2 ? LTGREEN : LTYELLOW) : REDISH)); btnPhasers.Background = ((Phasers.IsHealthy() ? LTGREEN : REDISH)); btnLRS.Background = ((LRS.IsHealthy() ? GREENISH : REDISH)); btnRepairs.Background = (DamageControl.HealthPercent() > 50 ? GREENISH : (DamageControl.IsHealthy() ? LTYELLOW : REDISH)); btnDivert.Background = (Shields.levelPercent() > 80 ? GREENISH : (Shields.levelPercent() < 40 ? REDISH : LTYELLOW)); btnDivert.IsEnabled = !IsDocked(); btnShields.IsEnabled = !IsDocked(); if (this.alertLevel == REDALERT) { if (Shields.HealthPercent() > 60) { btnShields.Background = (Shields.AreUp() ? GREENISH : REDISH); } else { btnShields.Background = ((Shields.IsHealthy() && Shields.AreUp() ? LTYELLOW : REDISH)); } } else { if (Shields.HealthPercent() > 30) { btnShields.Background = (Shields.AreUp() ? GREENISH : LTGREEN); } else { btnShields.Background = ((Shields.IsHealthy() ? (Shields.AreUp() ? LTGREEN : LTYELLOW) : REDISH)); } } })); // are we docked? Debug("Docked"); SetDocked(SRS.AreWeDocked()); // look for starbase updates Debug("Starbases"); StarBases.Execute(); // execute damage control and LRS updates Debug("DC"); DamageControl.Execute(); // update the Long range sensors Debug("LRS"); LRS.Execute(); Debug("Exiting setcondition"); }
public void Connect(string port) { amp = new SRS(port); knob1.Value = (int)amp.scaler; tmrUpdate.Start(); }
//指定表名读出成一个FeatureSource public FeatureSource ReadFromTable(string table) { string connStr = "Server=" + server + ";Port=" + port + ";UserId=" + user + ";Password="******";Database=" + database + ";"; try { //获得图层类型和参考坐标系 Dictionary <string, string> dt1 = GetSchemePara(table); OSGeo.OGR.wkbGeometryType geometryType = String2Type.String2wkbGeometryType(dt1["type"]); ReferenceSystem rs = new SRS(new OSGeo.OSR.SpatialReference(Int2SRText(int.Parse(dt1["srid"])))); NpgsqlConnection conn = new NpgsqlConnection(connStr); conn.Open(); IDbCommand dbcmd = conn.CreateCommand(); dbcmd.CommandText = "SELECT *,ST_AsText(geom) AS geom1 FROM \"" + table + "\""; IDataReader dr = dbcmd.ExecuteReader(); Dictionary <string, OSGeo.OGR.FieldDefn> fields = new Dictionary <string, OSGeo.OGR.FieldDefn>(); string[] fieldNames = new string[dr.FieldCount - 2]; for (int i = 0; i < dr.FieldCount - 2; i++) { OSGeo.OGR.FieldDefn d = GetFieldDefn(dr.GetName(i), dr.GetDataTypeName(i)); fields.Add(dr.GetName(i), d); fieldNames[i] = dr.GetName(i); } Schema schema = new Schema(table, geometryType, rs, fields); List <Feature> flst = new List <Feature>(); while (dr.Read()) { int featureID = int.Parse(dr[0].ToString()); Geometry.Geometry geometry = WKT2Feature.WKT2Geometry(dr[dr.FieldCount - 1].ToString()); Dictionary <string, Object> attributes = new Dictionary <string, object>(); for (int i = 0; i < dr.FieldCount - 2; i++) { Object o; switch (fields[fieldNames[i]].GetFieldType()) { case OSGeo.OGR.FieldType.OFTInteger: o = int.Parse(dr[i].ToString()); break; case OSGeo.OGR.FieldType.OFTReal: o = double.Parse(dr[i].ToString()); break; default: o = dr[i].ToString(); break; } attributes.Add(fieldNames[i], o); } Feature feature = new Feature(featureID, schema, geometry, attributes); flst.Add(feature); } FeatureCollection fc = new FeatureCollection(flst); FeatureSource fs = new FeatureSource(schema, fc); return(fs); conn.Close(); } catch (Exception e) { return(null); } }