private void AddNewPlane(Plane.Plane Add) { Planes planonovic = new Planes(); planonovic.New = Add; CurrentPlanes.Add(planonovic); }
private void UpdateExistingPlane(Plane.Plane Update) { int index = CurrentPlanes.FindIndex(p => p.New == Update); CurrentPlanes[index].Old = CurrentPlanes[index].New; CurrentPlanes[index].New = Update; CalculateNewData(index); }
private void printNewPlane(Plane.Plane plane) { int alt = plane.Altitude; string _ID = plane.ID; int xPos = plane.XPosition; int yPos = plane.YPosition; logger.LogText($"|{_ID, -7}|{alt,-20}|{xPos,-20}|{yPos,-20}|"); logger.LogText("------------------------------------------------------------------------"); }
/// <summary>Adds planes to the map based on a string, used for LAN games</summary> /// <param name="InText">The specified string.</param> /// <param name="InQ">The list of planes to add to the map.</param> public void TextAddPlanes(string InText, List <Plane.Plane> InQ) { string[] inp = InText.Split(LanHost.FieldDelimiter.ToCharArray()); for (int i = 0; i < inp.Length;) { Plane.Plane t = (Plane.Plane)InQ[int.Parse(inp[i++])].Clone(); t.Location[0] = int.Parse(inp[i++]); t.Location[1] = int.Parse(inp[i++]); Map.AddPlane(t); } }
private void printPlaneUpdate(Plane.Plane plane) { int alt = plane.Altitude; string _ID = plane.ID; int xPos = plane.XPosition; int yPos = plane.YPosition; double heading = plane.Heading; double HorizontalSpeed = plane.HorizontalSpeed; logger.LogText($"|{_ID, -7}|{alt, -20}|{xPos,-20}|{yPos,-20}|{heading,-20}|{HorizontalSpeed,-28}|"); logger.LogText("--------------------------------------------------------------------------------------------------------------------------"); }
private void CalculateNewData(int index) { Plane.Plane p1 = CurrentPlanes[index].Old; Plane.Plane p2 = CurrentPlanes[index].New; int deltaX = p2.XPosition - p1.XPosition; int deltaY = p2.YPosition - p1.YPosition; double time = (p2.TimeStamp - p1.TimeStamp).TotalMilliseconds; CurrentPlanes[index].New.Heading = Calculator.Calculator.GetCurrentHeading(deltaX, deltaY); CurrentPlanes[index].New.HorizontalSpeed = Calculator.Calculator.GetCurrentSpeed(deltaX, deltaX, time); }
public Plane.Plane FormatFromString(String planeinfo) { Plane.Plane planeicus = new Plane.Plane(); String[] planeInfoSplit = planeinfo.Split(';'); planeicus.ID = planeInfoSplit[0]; planeicus.XPosition = Convert.ToInt32(planeInfoSplit[1]); planeicus.YPosition = Convert.ToInt32(planeInfoSplit[2]); planeicus.Altitude = Convert.ToInt32(planeInfoSplit[3]); string format = "yyyyMMddHHmmssfff"; planeicus.TimeStamp = DateTime.ParseExact(planeInfoSplit[4], format, CultureInfo.InvariantCulture); //ATR423; 39045; 12932; 14000; 20151006213456789 return(planeicus); }
/// <summary>Randomly adds planes to the map. Used for the AI</summary> /// <param name="InQ">The list of planes to add to the map.</param> public void RandomAddPlanes(List <Plane.Plane> InQ) { Random rng = new Random(); int InQIndex = 0; foreach (Ship.Ship i in Map.Ships) { if (i.CanCarryPlanes) { for (int j = 0; InQIndex < InQ.Count && j < i.BodyList().Length; j++) { Plane.Plane temp = (Plane.Plane)InQ[InQIndex++].Clone(); temp.Location[0] = i.BodyList()[j][0]; temp.Location[1] = i.BodyList()[j][1]; Map.AddPlane(temp); } if (InQIndex >= InQ.Count) { return; } } } }
/// <summary>Adds planes to the map based on user input</summary> /// <param name="InpPlanes">The list of planes to add to the map.</param> /// <returns>A string representation of the set up pattern of the planes, used for LAN games</returns> public string ManualAddPlanes(List <Plane.Plane> InpPlanes) { Map.SettingUpPlanes = true; List <Plane.Plane> q = new List <Plane.Plane>(); int num = 0; foreach (Plane.Plane i in InpPlanes) { Plane.Plane t = (Plane.Plane)i.Clone(); t.Number = num++; q.Add(t); } bool movingExisting = false; MapIndexSelected = 0; QIndexSelected = 0; do { if (!movingExisting) { Map.SelectedPlane = q[QIndexSelected]; } else { Map.SelectedPlane = Map.FPlanes[MapIndexSelected]; } Console.Clear(); Map.PrintMap(true, Map.Display.Plane, -1); if (Map.SelectedPlane != null) { Console.WriteLine("Plane selected: " + Map.SelectedPlane.PlaneName); } ; string t = ""; if (Map.SelectedPlane.Attacks != null) { foreach (Attack.Attack i in Map.SelectedPlane.Attacks) { t += ", " + i.AttackString; } t = t.Substring(1, t.Length - 1); } Console.WriteLine("Attacks:" + t); if (movingExisting) { Console.WriteLine("The plane selected has been placed on the map, use \"c\" to pick it up."); } else { Game.DisplayControl("The plane selected has not been placed on the map, use SPACE to place it.", Map.CanPlaceFPlane(Map.SelectedPlane)); } Console.WriteLine(); Console.WriteLine("Use arrow keys to change the plane's location"); Game.DisplayControl("Use R/T to select planes that have not been placed.", q.Count > 0); Game.DisplayControl("Use F/G to select planes that have been placed.", Map.FPlanes.Count > 0); Game.DisplayControl("Use ENTER to finish placing planes when all planes have been placed.", q.Count <= 0); ConsoleKey k; switch (k = Console.ReadKey().Key) { case ConsoleKey.RightArrow: case ConsoleKey.UpArrow: case ConsoleKey.LeftArrow: case ConsoleKey.DownArrow: if (!movingExisting) { AttemptMove(Map.SelectedPlane, k); } break; case ConsoleKey.R: case ConsoleKey.T: if (q.Count > 0) { if (!movingExisting) { Program.AdjustListSelected(ref QIndexSelected, k, q.Count); } else { movingExisting = false; } } break; case ConsoleKey.Spacebar: if (!movingExisting && Map.CanPlaceFPlane(Map.SelectedPlane)) { Map.AddPlane(Map.SelectedPlane); q.Remove(Map.SelectedPlane); if (q.Count == 0) { movingExisting = true; } Program.WrapAdd(ref QIndexSelected, 0, q.Count); } break; case ConsoleKey.F: case ConsoleKey.G: if (Map.FPlanes.Count > 0) { if (movingExisting) { Program.AdjustListSelected(ref MapIndexSelected, k, Map.FPlanes.Count); } else { movingExisting = true; } } break; case ConsoleKey.C: if (movingExisting) { movingExisting = false; q.Insert(QIndexSelected, Map.SelectedPlane); Map.FPlanes.Remove(Map.SelectedPlane); Program.WrapAdd(ref MapIndexSelected, 0, Map.FPlanes.Count); } break; case ConsoleKey.Enter: if (q.Count == 0) { string outp = ""; foreach (Plane.Plane i in Map.FPlanes) { outp += i.Number + LanHost.FieldDelimiter + i.Location[0] + LanHost.FieldDelimiter + i.Location[1] + LanHost.FieldDelimiter; } return(outp.Substring(0, outp.Length - LanHost.FieldDelimiter.Length)); } break; } } while (true); }