ThreatSourceLibaray/tools/Program.cs

217 lines
8.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ThreatSource.Utils;
using ThreatSource.Jammer;
using System;
using System.Threading;
namespace ThreatSource.Tools.MissileSimulation
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("综合导弹模拟程序启动...");
var simulator = new ComprehensiveMissileSimulator();
// 标记是否收到仿真结束事件
var simulationEndedEvent = new ManualResetEvent(false);
// 订阅仿真结束事件
simulator.SimulationEnded += (sender, e) => {
simulationEndedEvent.Set();
};
while (true)
{
// 显示主菜单如果返回false则退出程序
if (!ShowMainMenu(simulator))
{
break;
}
// 重置事件状态
simulationEndedEvent.Reset();
// 开始仿真
var simulationThread = new Thread(simulator.Start);
simulationThread.Start();
// 等待退出命令
Console.WriteLine("\n仿真已开始运行。输入 'exit' 退出程序。");
bool exitProgram = false;
while (true)
{
if (Console.KeyAvailable)
{
var input = Console.ReadLine();
if (input?.ToLower() == "exit")
{
simulator.Stop();
exitProgram = true;
break;
}
}
// 检查仿真是否结束
if (simulationEndedEvent.WaitOne(100)) // 等待100ms
{
break;
}
}
if (exitProgram)
{
break;
}
// 等待仿真线程完全结束
simulationThread.Join();
// 显示分隔线和新的仿真选项
Console.WriteLine("\n" + new string('=', 50));
Console.WriteLine("当前导弹仿真结束。");
Console.WriteLine("按任意键返回主菜单,或输入 'exit' 退出程序...");
Console.WriteLine(new string('=', 50) + "\n");
string userInput = Console.ReadLine()?.ToLower() ?? string.Empty;
if (userInput == "exit")
{
break;
}
}
Console.WriteLine("\n程序已退出。");
}
static bool ShowMainMenu(ComprehensiveMissileSimulator simulator)
{
Console.WriteLine("=== 导弹仿真系统主菜单 ===\n");
// 第一步:选择导弹
if (!SelectMissile(simulator))
return false;
// 第二步:配置传感器
if (!ConfigureSensors(simulator))
return false;
// 第三步:配置干扰
if (!ConfigureJamming(simulator))
return false;
return true;
}
static bool SelectMissile(ComprehensiveMissileSimulator simulator)
{
var missiles = new[]
{
("LSGM_1", "激光半主动制导导弹"),
("LBRM_1", "激光驾束制导导弹"),
("TSM_1", "末敏弹"),
("ICGM_1", "红外指令制导导弹"),
("ITGM_1", "红外成像末制导导弹"),
("MMWG_1", "毫米波末制导导弹")
};
while (true)
{
Console.WriteLine("\n第一步请选择导弹类型");
for (int i = 0; i < missiles.Length; i++)
{
Console.WriteLine($" {i + 1}. {missiles[i].Item2}");
}
Console.WriteLine(" exit. 退出程序");
var input = Console.ReadLine()?.ToLower();
if (input == "exit")
return false;
if (int.TryParse(input, out int choice) &&
choice >= 1 && choice <= missiles.Length)
{
simulator.SelectMissile(missiles[choice - 1].Item1);
return true;
}
Console.WriteLine("无效选择,请重试");
}
}
static bool ConfigureSensors(ComprehensiveMissileSimulator simulator)
{
while (true)
{
Console.WriteLine("\n第二步配置传感器和指示器");
Console.WriteLine("当前传感器状态:");
var indicators = simulator.GetActiveIndicators();
for (int i = 0; i < indicators.Length; i++)
{
Console.WriteLine($" {i + 1}. {indicators[i].Name} [{(indicators[i].IsActive ? "" : "")}]");
}
Console.WriteLine(" 0. 继续下一步");
Console.WriteLine(" exit. 退出程序");
var input = Console.ReadLine()?.ToLower();
if (input == "exit")
return false;
if (int.TryParse(input, out int choice))
{
if (choice == 0) return true;
if (choice >= 1 && choice <= indicators.Length)
{
simulator.ToggleIndicator(indicators[choice - 1].Id);
continue;
}
}
Console.WriteLine("无效选择,请重试");
}
}
static bool ConfigureJamming(ComprehensiveMissileSimulator simulator)
{
var jammingTypes = new[]
{
(JammingType.Infrared, "红外干扰"),
(JammingType.MillimeterWave, "毫米波干扰"),
(JammingType.Laser, "激光干扰"),
(JammingType.SmokeScreen, "水平烟幕弹"),
(JammingType.SmokeScreen, "红外烟幕弹"),
(JammingType.SmokeScreen, "顶部烟幕弹"),
(JammingType.Decoy, "假目标干扰")
};
var jammingStatus = new bool[jammingTypes.Length];
while (true)
{
Console.WriteLine("\n第三步配置干扰方式");
Console.WriteLine("当前干扰状态:");
for (int i = 0; i < jammingTypes.Length; i++)
{
Console.WriteLine($" {i + 1}. {jammingTypes[i].Item2} [{(jammingStatus[i] ? "" : "")}]");
}
Console.WriteLine(" 0. 开始仿真");
Console.WriteLine(" exit. 退出程序");
var input = Console.ReadLine()?.ToLower();
if (input == "exit")
return false;
if (int.TryParse(input, out int choice))
{
if (choice == 0) return true;
if (choice >= 1 && choice <= jammingTypes.Length)
{
jammingStatus[choice - 1] = !jammingStatus[choice - 1];
if (jammingStatus[choice - 1])
simulator.ApplyJamming(jammingTypes[choice - 1].Item1, jammingTypes[choice - 1].Item2, 100, 5, new Vector3D(0, 0, 0));
else
simulator.ClearJamming(jammingTypes[choice - 1].Item1, jammingTypes[choice - 1].Item2);
continue;
}
}
Console.WriteLine("无效选择,请重试");
}
}
}
}