private void DisplayGalaticRecord() { Console.WriteLine(); StringBuilder sb = new StringBuilder(); Console.WriteLine("-------------------------------------------------"); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { sb.Append("| "); int klingonCount = 0; int starbaseCount = 0; int starCount = 0; Quadrant quadrant = quadrants[i, j]; if (quadrant.scanned) { klingonCount = quadrant.klingons; starbaseCount = quadrant.starbase ? 1 : 0; starCount = quadrant.stars; } sb.Append(string.Format("{0}{1}{2} ", klingonCount, starbaseCount, starCount)); } sb.Append("|"); Console.WriteLine(sb.ToString()); sb.Length = 0; Console.WriteLine("-------------------------------------------------"); } Console.WriteLine(); }
private void ShortRangeScan() { if (shortRangeScanDamage > 0) { Console.WriteLine("Short range scanner is damaged. Repairs are underway."); Console.WriteLine(); } else { Quadrant quadrant = quadrants[quadrantY, quadrantX]; quadrant.scanned = true; PrintSector(quadrant); } Console.WriteLine(); }
private void GenerateSector() { Quadrant quadrant = quadrants[quadrantY, quadrantX]; bool starbase = quadrant.starbase; int stars = quadrant.stars; int klingons = quadrant.klingons; klingonShips.Clear(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { sector[i, j] = SectorType.Empty; } } sector[sectorY, sectorX] = SectorType.Enterprise; while (starbase || stars > 0 || klingons > 0) { int i = random.Next(8); int j = random.Next(8); if (IsSectorRegionEmpty(i, j)) { if (starbase) { starbase = false; sector[i, j] = SectorType.Starbase; starbaseY = i; starbaseX = j; } else if (stars > 0) { sector[i, j] = SectorType.Star; stars--; } else if (klingons > 0) { sector[i, j] = SectorType.Kligon; KlingonShip klingonShip = new KlingonShip(); klingonShip.shieldLevel = 300 + random.Next(200); klingonShip.sectorY = i; klingonShip.sectorX = j; klingonShips.Add(klingonShip); klingons--; } } } }
private void PrintSector(Quadrant quadrant) { string condition = "GREEN"; if (quadrant.klingons > 0) { condition = "RED"; } else if (energy < 300) { condition = "YELLOW"; } StringBuilder sb = new StringBuilder(); Console.WriteLine("-=--=--=--=--=--=--=--=- Region: {0}", quadrant.name); PrintSectorRow(sb, 0, string.Format(" Quadrant: [{0},{1}]", quadrantX + 1, quadrantY + 1)); PrintSectorRow(sb, 1, string.Format(" Sector: [{0},{1}]", sectorX + 1, sectorY + 1)); PrintSectorRow(sb, 2, string.Format(" Stardate: {0}", stardate)); PrintSectorRow(sb, 3, string.Format(" Time remaining: {0}", timeRemaining)); PrintSectorRow(sb, 4, string.Format(" Condition: {0}", condition)); PrintSectorRow(sb, 5, string.Format(" Energy: {0}", energy)); PrintSectorRow(sb, 6, string.Format(" Shields: {0}", shieldLevel)); PrintSectorRow(sb, 7, string.Format(" Photon Torpedoes: {0}", photonTorpedoes)); Console.WriteLine("-=--=--=--=--=--=--=--=- Docked: {0}", docked); if (quadrant.klingons > 0) { Console.WriteLine(); Console.WriteLine("Condition RED: Klingon ship{0} detected.", (quadrant.klingons == 1 ? "" : "s")); if (shieldLevel == 0 && !docked) { Console.WriteLine("Warning: Shields are down."); } } else if (energy < 300) { Console.WriteLine(); Console.WriteLine("Condition YELLOW: Low energy level."); condition = "YELLOW"; } }
private void LongRangeScan() { if (longRangeScanDamage > 0) { Console.WriteLine("Long range scanner is damaged. Repairs are underway."); Console.WriteLine(); return; } StringBuilder sb = new StringBuilder(); Console.WriteLine("-------------------"); for (int i = quadrantY - 1; i <= quadrantY + 1; i++) { for (int j = quadrantX - 1; j <= quadrantX + 1; j++) { sb.Append("| "); int klingonCount = 0; int starbaseCount = 0; int starCount = 0; if (i >= 0 && j >= 0 && i < 8 && j < 8) { Quadrant quadrant = quadrants[i, j]; quadrant.scanned = true; klingonCount = quadrant.klingons; starbaseCount = quadrant.starbase ? 1 : 0; starCount = quadrant.stars; } sb.Append(string.Format("{0}{1}{2} ", klingonCount, starbaseCount, starCount)); } sb.Append("|"); Console.WriteLine(sb.ToString()); sb.Length = 0; Console.WriteLine("-------------------"); } Console.WriteLine(); }
private void InitializeGame() { quadrantX = random.Next(8); quadrantY = random.Next(8); sectorX = random.Next(8); sectorY = random.Next(8); stardate = random.Next(50) + 2250; energy = 3000; photonTorpedoes = 10; timeRemaining = 40 + random.Next(10); klingons = 15 + random.Next(6); starbases = 2 + random.Next(3); destroyed = false; navigationDamage = 0; shortRangeScanDamage = 0; longRangeScanDamage = 0; shieldControlDamage = 0; computerDamage = 0; photonDamage = 0; phaserDamage = 0; shieldLevel = 0; docked = false; List <string> names = new List <string>(); foreach (string name in quadrantNames) { names.Add(name); } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { int index = random.Next(names.Count); Quadrant quadrant = new Quadrant(); quadrants[i, j] = quadrant; quadrant.name = names[index]; quadrant.stars = 1 + random.Next(8); names.RemoveAt(index); } } int klingonCount = klingons; int starbaseCount = starbases; while (klingonCount > 0 || starbaseCount > 0) { int i = random.Next(8); int j = random.Next(8); Quadrant quadrant = quadrants[i, j]; if (!quadrant.starbase) { quadrant.starbase = true; starbaseCount--; } if (quadrant.klingons < 3) { quadrant.klingons++; klingonCount--; } } }