예제 #1
0
        public DiscoveryDrone(DiscoveryDroneConfig config, TileType[,] map)
        {
            this.Config = config;

            this.random          = new Random();
            this.timer           = new Timer(config.MoveInterval * 1000);
            this.timer.Elapsed  += (sender, evantArgs) => this.Move();
            this.timer.AutoReset = true;

            this.status = new DiscoveryDroneStatus(this.Config.Name, config.PositionX, config.PositionY, map);

            this.handlers = new Dictionary <Type, Action <IMessage> >();
            this.handlers.Add(typeof(ReportStatusMessage), this.ReportStatusMessageHandler);
            this.handlers.Add(typeof(StartMovingMessage), this.StartMovingHandler);
            this.handlers.Add(typeof(StopMovingMessage), this.StopMovingHandler);
        }
 public AddDiscoveryDroneMessage(DiscoveryDroneConfig droneConfig)
 {
     this.DroneConfig = droneConfig;
 }
예제 #3
0
        static void UserInputHandler(string input)
        {
            try
            {
                if (input.StartsWith(UserCommands.ShowMap))
                {
                    var split = input.Split(' ');

                    GetMapHandler(split.Count() == 1 ? "world" : split[1]);
                }
                else if (input == UserCommands.Help)
                {
                    Console.WriteLine(GetHelp());
                }
                else if (input == UserCommands.Demo)
                {
                    Demo();
                }
                else if (input.StartsWith(UserCommands.MonitorStart))
                {
                    var split = input.Split(' ');
                    if (split.Count() == 3)
                    {
                        monitoredEntity = split[2];
                    }
                    monitorTimer.Start();
                }
                else if (input.StartsWith(UserCommands.MonitorStop))
                {
                    monitorTimer.Stop();
                }
                else if (input.StartsWith(UserCommands.StartDrone))
                {
                    actorSystem.ActorSelection($"akka://{actorSystem.Name}/user/world/relay/").Tell(new StartMovingMessage(input.Split(' ')[1]), console);
                }
                else if (input.StartsWith(UserCommands.StopDrone))
                {
                    actorSystem.ActorSelection($"akka://{actorSystem.Name}/user/world/relay/").Tell(new StopMovingMessage(input.Split(' ')[1]), console);
                }
                else if (input.StartsWith(UserCommands.AddDrone))
                {
                    var split               = input.Split(' ');
                    var droneName           = split[1];
                    var dronePositionX      = int.Parse(split[2]);
                    var dronePositionY      = int.Parse(split[3]);
                    var droneTurnLikeliness = float.Parse(split[4].Replace('.', ','));
                    var moveInterval        = int.Parse(split[5]);



                    var config = new DiscoveryDroneConfig(
                        droneName,
                        dronePositionX,
                        dronePositionY,
                        droneTurnLikeliness,
                        2,
                        moveInterval);

                    var message = new AddDiscoveryDroneMessage(config);

                    actorSystem.ActorSelection($"akka://{actorSystem.Name}/user/world/relay/").Tell(message, console);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine(GetHelp());
            }

            string GetHelp()
            {
                return("Ussage:" +
                       $"{Environment.NewLine}{UserCommands.Help} - show this help message" +
                       $"{Environment.NewLine}{UserCommands.Demo} - about 60 seconds demo of the system with commentary" +
                       $"{Environment.NewLine}{UserCommands.ShowMap} <whose> - show <whose> map" +
                       $"{Environment.NewLine}{UserCommands.AddDrone} <name> <int positionX> <int positionY> <float turnTikeliness> <moveInterval>" +
                       $"{Environment.NewLine}{UserCommands.StartDrone} <name> - call next step" +
                       $"{Environment.NewLine}{UserCommands.StopDrone} <name> - call next step" +
                       $"{Environment.NewLine}{UserCommands.MonitorStart} <name> - start monitoring <name> map" +
                       $"{Environment.NewLine}{UserCommands.MonitorStop} - call next step" +
                       $"{Environment.NewLine}{UserCommands.Exit} - exit the application");
            }
        }