示例#1
0
        private void Percive()
        {
            var perciveTask = world.Ask <MapUpdate>(new UpdateMapMessage(this.status.PositionX, this.status.PositionY, this.Config.Vision));

            perciveTask.Wait(); //TODO: przyjmij mapę

            var patch = perciveTask.Result;

            this.status = this.status.UpdateMap(MapHelper.GetUpdatedMap(this.status.Map, patch));
        }
示例#2
0
        private void AddDroneHandler(IMessage message)
        {
            var parsed = message as AddDiscoveryDroneMessage;

            var unchartedMap = MapHelper.GetUnchartedMap(this.worldSizeX, this.worldSizeY);

            var newDrone = Context.ActorOf(Props.Create <DiscoveryDrone>(parsed.DroneConfig, unchartedMap), parsed.DroneConfig.Name);

            var status = new DiscoveryDroneStatus(parsed.DroneConfig.Name, parsed.DroneConfig.PositionX, parsed.DroneConfig.PositionY, unchartedMap);

            this.dronesStatuses.Add(parsed.DroneConfig.Name, status);

            Context.ActorSelection($"akka://{Context.System.Name}/user/world").Tell(new StatusReportMessage(status));
        }
示例#3
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);
        }
示例#4
0
        private void Move()
        {
            if (this.random.NextDouble() <= this.Config.TurnLikelines)
            {
                this.ChangeDirection();
            }

            bool moved = false;

            while (!moved)
            {
                switch (this.moveDirection)
                {
                case MoveDirection.Up:
                {
                    if (this.CanMoveTo(this.status.PositionX, this.status.PositionY + 1))
                    {
                        this.status = this.status.Move(this.status.PositionX, this.status.PositionY + 1);
                        moved       = true;
                    }
                    break;
                }

                case MoveDirection.Right:
                {
                    if (this.CanMoveTo(this.status.PositionX + 1, this.status.PositionY))
                    {
                        this.status = this.status.Move(this.status.PositionX + 1, this.status.PositionY);
                        moved       = true;
                    }
                    break;
                }

                case MoveDirection.Down:
                {
                    if (this.CanMoveTo(this.status.PositionX, this.status.PositionY - 1))
                    {
                        this.status = this.status.Move(this.status.PositionX, this.status.PositionY - 1);
                        moved       = true;
                    }
                    break;
                }

                case MoveDirection.Left:
                {
                    if (this.CanMoveTo(this.status.PositionX - 1, this.status.PositionY))
                    {
                        this.status = this.status.Move(this.status.PositionX - 1, this.status.PositionY);
                        moved       = true;
                    }
                    break;
                }
                }
                if (!moved)
                {
                    this.ChangeDirection();
                }
            }

            Percive();
            this.parent.Tell(new StatusReportMessage(this.status));
            world.Tell(new StatusReportMessage(this.status));
        }
 public StatusReportMessage(DiscoveryDroneStatus status)
 {
     this.Status = status;
 }