/// <summary>Preforms a turn based on a string. Used for LAN games</summary> /// <param name="Text">The specified string.</param> public override void DoTextTurn(string Text) { string[] inArray = Text.Split(IndexDelimiter.ToCharArray()); EnemyMap.ETargetLocation[0] = int.Parse(inArray[0]); EnemyMap.ETargetLocation[1] = int.Parse(inArray[1]); FriendlyMap.FTargetLocation[0] = int.Parse(inArray[2]); FriendlyMap.FTargetLocation[1] = int.Parse(inArray[3]); SelectedOption = int.Parse(inArray[4]); UsingSelectedAttack = bool.Parse(inArray[5]); UsingSelectedAA = bool.Parse(inArray[6]); for (int i = 0; i < SelectedIndex[SelectedOption].Length; i++) SelectedIndex[SelectedOption][i] = int.Parse(inArray[7 + i]); UpdateMapData(); switch (SelectedOption) { case 0: EnemyMap.AdvancedFire(false, false, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; case 1: EnemyMap.AdvancedFire(true, false, EnemyMap.SelectedPlane.Attacks, SelectedIndex[SelectedOption][2]); break; case 2: FriendlyMap.SelectedPlane.Location = new int[] { EnemyMap.ETargetLocation[0], EnemyMap.ETargetLocation[1] }; EnemyMap.EPlanes.Add(FriendlyMap.SelectedPlane); FriendlyMap.FPlanes.Remove(FriendlyMap.SelectedPlane); break; case 3: EnemyMap.SelectedPlane.Location = new int[] { FriendlyMap.FTargetLocation[0], FriendlyMap.FTargetLocation[1] }; EnemyMap.EPlanes.Remove(EnemyMap.SelectedPlane); FriendlyMap.FPlanes.Add(EnemyMap.SelectedPlane); break; case 4: FriendlyMap.AdvancedFire(false, true, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; } }
/// <summary>Preforms a turn based on user input</summary> /// <returns>A bool representing if the player scored a hit during the turn</returns> public override bool DoManualTurn() { SelectedOption = 0; SetSelectedIndex(); UpdateMapData(); do { Console.Clear(); Console.Write("Options available: "); Game.DisplayControlKey("1 ", true); Game.DisplayControlKey("2 ", EnemyMap.EPlanes.Count > 0); Game.DisplayControlKey("3 ", FriendlyMap.FPlanes.Count > 0); Game.DisplayControlKey("4 ", EnemyMap.EPlanes.Count > 0); Game.DisplayControlKey("5 ", FriendlyMap.EPlanes.Count > 0 || EnemyMap.FPlanes.Count > 0); Console.WriteLine(); Console.Write("Selected option (Use # to change): " + (SelectedOption + 1).ToString() + "."); Map AdjustingMap = null; switch (SelectedOption) { case 0: Console.WriteLine("attack ships"); EnemyMap.PrintMap(false, EnemyMap.SelectedAttack != null ? Map.Display.Attack : Map.Display.Center, SelectedIndex[SelectedOption][2]); FriendlyMap.PrintMap(true, UsingSelectedAttack ? Map.Display.Ship : Map.Display.Nothing, -1); Console.WriteLine("\nShip: " + (UsingSelectedAttack ? FriendlyMap.Selected.ShipName : "none")); Console.WriteLine("Attack: " + (EnemyMap.SelectedAttack == null ? "default" : EnemyMap.SelectedAttack.AttackString)); if (EnemyMap.SelectedAttack != null) Console.WriteLine("Firing pattern: " + (1 + SelectedIndex[0][2]).ToString() + "/" + EnemyMap.SelectedAttack.SplashDamage.Length); Console.WriteLine(); Console.WriteLine("Use R/T to browse between ships, F/G for attacks and V/B for attack layout."); if (UsingSelectedAttack) Console.WriteLine("Use C deselect ship and use default attack"); Console.WriteLine("Use arrow keys to move selection, use enter to fire."); AdjustingMap = EnemyMap; break; case 1: Console.WriteLine("use aircraft"); EnemyMap.PrintMap(false, Map.Display.AttackingPlane, SelectedIndex[SelectedOption][2]); FriendlyMap.PrintMap(true, Map.Display.Nothing, -1); Console.WriteLine("Attack: " + (EnemyMap.SelectedAttack == null ? "nothing!" : (EnemyMap.SelectedAttack.AttackName + (EnemyMap.SelectedAttack.Amount > 0 ? " x"+ EnemyMap.SelectedAttack.Amount.ToString() : "")))); if (EnemyMap.SelectedAttack != null) Console.WriteLine("Firing pattern: " + (1 + SelectedIndex[0][2]).ToString() + "/" + EnemyMap.SelectedAttack.SplashDamage.Length); Console.WriteLine(); Console.WriteLine("Use R/T to browse between planes"); Game.DisplayControl("Use enter to fire.",EnemyMap.SelectedAttack != null); AdjustingMap = null; break; case 2: Console.WriteLine("deploy aircraft"); EnemyMap.PrintMap(false, Map.Display.Center, -1); FriendlyMap.PrintMap(true, Map.Display.Plane, -1); AdjustingMap = EnemyMap; Console.WriteLine(); Console.WriteLine("Use R/T to browse between planes."); Console.WriteLine("Use arrow keys to move selection."); Game.DisplayControl("Use enter to deploy.", EnemyMap.CanPlaceEPlane(EnemyMap.ETargetLocation)); break; case 3: Console.Write("recall aircraft"); EnemyMap.PrintMap(false, Map.Display.Plane, -1); FriendlyMap.PrintMap(true, Map.Display.Center, -1); Console.WriteLine(); Console.WriteLine("Use R/T to browse between planes."); Console.WriteLine("Use arrow keys to move selection."); Game.DisplayControl("Use enter to recall.", FriendlyMap.CanPlaceFPlane(FriendlyMap.FTargetLocation)); AdjustingMap = FriendlyMap; break; case 4: Console.WriteLine("AA"); AdjustingMap = FriendlyMap; FriendlyMap.PrintMap(true, FriendlyMap.SelectedAttack != null ? Map.Display.Attack : Map.Display.Center, SelectedIndex[SelectedOption][2]); FriendlyMap.PrintMap(true, Map.Display.Ship, -1); Console.WriteLine("Ship: " + (UsingSelectedAA ? FriendlyMap.Selected.ShipName : "none")); Console.WriteLine("\nAA: " + (FriendlyMap.SelectedAttack == null ? "default" : FriendlyMap.SelectedAttack.AttackString)); if (FriendlyMap.SelectedAttack != null) Console.WriteLine("Firing pattern: " + (1 + SelectedIndex[4][2]).ToString() + "/" + FriendlyMap.SelectedAttack.SplashDamage.Length); Console.WriteLine(); Console.WriteLine("Use R/T to browse between ships, F/G for attacks and V/B for attack layout."); if (UsingSelectedAA) Console.WriteLine("Use C deselect ship and use default attack"); Console.WriteLine("Use arrow keys to move selection, use enter to fire."); break; } System.ConsoleKey k; switch (k = Console.ReadKey().Key) { case ConsoleKey.UpArrow: case ConsoleKey.DownArrow: case ConsoleKey.LeftArrow: case ConsoleKey.RightArrow: AttemptMoveTarget(k, AdjustingMap); break; case ConsoleKey.D1: case ConsoleKey.D2: case ConsoleKey.D3: case ConsoleKey.D4: case ConsoleKey.D5: AttemptChangeOption(k); break; case ConsoleKey.R: case ConsoleKey.T: if (SelectedOption == 0 && UsingSelectedAttack) AttemptChangeSelectedIndex(0, k); else if (SelectedOption == 0) { UsingSelectedAttack = true; UpdateMapData(); } else if (SelectedOption == 4 && UsingSelectedAA) AttemptChangeSelectedIndex(0, k); else if (SelectedOption == 4) { UsingSelectedAA = true; UpdateMapData(); } else AttemptChangeSelectedIndex(0, k); break; case ConsoleKey.F: case ConsoleKey.G: AttemptChangeSelectedIndex(1, k); break; case ConsoleKey.V: case ConsoleKey.B: AttemptChangeSelectedIndex(2, k); break; case ConsoleKey.C: if (SelectedOption == 0 && UsingSelectedAttack) { UsingSelectedAttack = false; UpdateMapData(); } else if (SelectedOption == 4 && UsingSelectedAA) { UsingSelectedAA = false; UpdateMapData(); } break; case ConsoleKey.Enter: bool t = false; switch (SelectedOption) { case 0: t= EnemyMap.AdvancedFire(false, false, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; case 1: if (EnemyMap.SelectedAttack == null) continue; t = EnemyMap.AdvancedFire(true, false, EnemyMap.SelectedPlane.Attacks, SelectedIndex[SelectedOption][2]); break; case 2: if (!EnemyMap.CanPlaceEPlane(EnemyMap.ETargetLocation)) continue; FriendlyMap.SelectedPlane.Location = new int[] { EnemyMap.ETargetLocation[0], EnemyMap.ETargetLocation[1] }; EnemyMap.EPlanes.Add(FriendlyMap.SelectedPlane); FriendlyMap.FPlanes.Remove(FriendlyMap.SelectedPlane); break; case 3: if (!FriendlyMap.CanPlaceFPlane(FriendlyMap.FTargetLocation)) continue; EnemyMap.SelectedPlane.Location = new int[] { FriendlyMap.FTargetLocation[0], FriendlyMap.FTargetLocation[1] }; EnemyMap.EPlanes.Remove(EnemyMap.SelectedPlane); FriendlyMap.FPlanes.Add(EnemyMap.SelectedPlane); break; case 4: FriendlyMap.AdvancedFire(false, true, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; } string outp = "The results of your turn."; if (EnemyMap.DestroyedList.Count > 0) { outp += "\nThe following were destroyed on the enemy map: "; foreach (string i in EnemyMap.DestroyedList) outp += i + ", "; outp = outp.Substring(0, outp.Length - 2); EnemyMap.DestroyedList = new List<string>(); } if (FriendlyMap.DestroyedList.Count > 0) { outp += "\nThe following were destroyed over your map: "; foreach (string i in FriendlyMap.DestroyedList) outp += i + ", "; outp = outp.Substring(0, outp.Length - 2); FriendlyMap.DestroyedList = new List<string>(); } outp += "\nPress SPACE to continue."; Console.Clear(); EnemyMap.PrintMap(false, Map.Display.Nothing, -1); FriendlyMap.PrintMap(true, Map.Display.Nothing, -1); Console.Write(outp); do { } while (Console.ReadKey().Key != ConsoleKey.Spacebar); TurnText += EnemyMap.ETargetLocation[0].ToString() + IndexDelimiter + EnemyMap.ETargetLocation[1].ToString() + IndexDelimiter + FriendlyMap.FTargetLocation[0].ToString() + IndexDelimiter + FriendlyMap.FTargetLocation[1].ToString() + IndexDelimiter + SelectedOption + IndexDelimiter + UsingSelectedAttack + IndexDelimiter + UsingSelectedAA; for (int i = 0; i < SelectedIndex[SelectedOption].Length; i++) TurnText += IndexDelimiter + SelectedIndex[SelectedOption][i].ToString(); TurnText += TurnDelimiter; return t; } } while (true); }