Esempio n. 1
0
        private void UpdatePlane(Common.Plane plane)
        {
            string URL = String.Format("{0}/UpdatePlane?id={1}&passengerCount={2}&cargoCount={3}&fuelCount={4}",
                                       ServiceStrings.Vis, plane.Id, plane.Passengers.Count, plane.CargoCount, plane.FuelCount);

            CommonUtil.MakeRequest(URL);
        }
Esempio n. 2
0
        private static void MovePlane(Common.Plane plane, Zone zone)
        {
            string URL = String.Format("{0}/Move?type={1}&id={2}&zone={3}",
                                       ServiceStrings.Vis, (int)Entity.PLANE, plane.Id, (int)zone);

            CommonUtil.MakeRequest(URL);
            plane.State = EntityState.MOVING;
        }
Esempio n. 3
0
        private static void StartPlaneMaintenance(Common.Plane plane)
        {
            string URL = String.Format("{0}/StartService?id={1}&zone={2}",
                                       ServiceStrings.GrControl, plane.Id, (int)plane.CurrentZone);

            CommonUtil.MakeRequest(URL);
            plane.State = EntityState.STANDING_BY;
        }
Esempio n. 4
0
        private static void SpawnPlane(Common.Plane plane)
        {
            string URL = String.Format(
                "{0}/SpawnPlane?type={1}&id={2}&zone={3}&cargo={4}&passengerCount={5}&fuelCount={6}",
                ServiceStrings.Vis, (int)Entity.PLANE, plane.Id, (int)plane.CurrentZone, plane.CargoCount,
                plane.PassengerCount, plane.FuelCount);

            CommonUtil.MakeRequest(URL);
        }
Esempio n. 5
0
 // завершение движения - посадки или отлёта
 void IPlaneService.CompleteMove(string id, int zone)
 {
     lock (PlaneHandler.Planes)
     {
         Common.Plane plane = PlaneHandler.Planes.Find(x => x.Id.Equals(id));
         PlaneHandler.FreeHangar(plane.CurrentZone);
         plane.CurrentZone = (Zone)zone;
         plane.State       = EntityState.FINISHED_TASK;
     }
 }
Esempio n. 6
0
 public void GoAway(string id)
 {
     lock (PlaneHandler.Planes)
     {
         Common.Plane plane = PlaneHandler.Planes.Find(x => x.Id.Equals(id));
         if (plane == null)
         {
             return;
         }
         plane.State = EntityState.WAITING_FOR_COMMAND;
     }
 }
Esempio n. 7
0
 public void GeneratePlane(int passengerCount)
 {
     if (PlaneHandler.Planes.Count >= 8)
     {
         return;
     }
     Common.Plane plane = PlaneHandler.GeneratePlane(passengerCount);
     lock (PlaneHandler.Planes)
     {
         PlaneHandler.Planes.Add(plane);
     }
 }
Esempio n. 8
0
        private static void RemovePlane(Common.Plane plane)
        {
            string URL = String.Format("{0}/Despawn?id={1}",
                                       ServiceStrings.Vis, plane.Id);

            CommonUtil.MakeRequest(URL);
            Planes.Remove(plane);
            if (Planes.Count < 4)
            {
                int passengerCount = RandomGen.Next(1, Common.Plane.PassengerCapacity + 1);
                plane = GeneratePlane(passengerCount);
                Planes.Add(plane);
            }
        }
Esempio n. 9
0
        private static Common.Plane GeneratePlane()
        {
            int passengerCount = RandomGen.Next(1, Common.Plane.PassengerCapacity + 1);

            string planeId = Guid.NewGuid().ToString();
            //OpenRegistration?flightId={flightId}
            string URL = String.Format("{0}/OpenRegistration?flightId={1}", ServiceStrings.RegStand, planeId);

            Util.MakeRequest(URL);
            URL = String.Format("{0}/GeneratePassengers?id={1}&count={2}", ServiceStrings.Passenger, planeId, passengerCount);
            string           passengerString  = Util.MakeRequest(URL);
            RegistrationList registrationList = JsonConvert.DeserializeObject <RegistrationList>(passengerString);
            int fuelCount = RandomGen.Next(Common.Plane.MIN_GENERATED_FUEL, Common.Plane.MAX_GENERATED_FUEL + 1);

            Common.Plane plane = new Common.Plane(planeId, registrationList.Passengers, registrationList.CargoCount, fuelCount);
            return(plane);
        }
Esempio n. 10
0
        public static void HandlePlanes()
        {
            // все изменения списка самолётов проводятся ТОЛЬКО в основном цикле
            // веб-методы только меняют состояния уже существующих объектов
            int activePlanes = 0;

            while (true)
            {
                Thread.Sleep(1000);
                lock (Planes)
                {
//                    Util.Log(@"F:\Programming\CPP\Winsock\Aeroport\Plane\log"+ (iter++) +".txt", JsonConvert.SerializeObject(Planes));
                    // в данном цикле обрабатываются только те действия, которые инициируются самим самолётом
                    for (int i = 0; i < Planes.Count; i++)
                    {
                        Common.Plane plane = Planes[i];
                        // если самолёт находится в движении, то пропускаем его - ждём, пока закончит
                        if (plane.State == EntityState.MOVING)
                        {
                            continue;
                        }

                        // дальше действия зависят от текущей локации самолёта
                        // движение не рассматриваем

                        //если самолёт находится в воздухе
                        if (plane.CurrentZone == Zone.PLANE_SPAWN)
                        {
                            // если самолёт закончил движение, то его можно убрать и сгенерить новый
                            if (plane.State == EntityState.FINISHED_TASK)
                            {
                                string URL = String.Format("http://localhost:{0}/VisualizerService.svc/Despawn?id={1}", Ports.Visualizer, plane.Id);
                                Util.MakeRequest(URL);
                                Planes.Remove(plane);
                                plane = GeneratePlane();
                                Planes.Add(plane);
                                activePlanes--;
                            }
                            // если самолёт ждёт разрешения на посадку, то проверяем свободные полосы
                            else if (plane.State == EntityState.WAITING_FOR_COMMAND)
                            {
                                if (activePlanes < 2)
                                {
                                    activePlanes++;
                                    int landingDelay = RandomGen.Next(1, 5);
                                    plane.ActionTime = DateTime.Now + TimeSpan.FromSeconds(landingDelay);
                                    plane.HasAction  = true;
                                    plane.State      = EntityState.STANDING_BY;
                                }
                            }
                            // если самолёт ждёт своей очереди на посадку, то проверяем, пришло ли его время
                            else if (plane.State == EntityState.STANDING_BY)
                            {
                                // если время пришло, то спавним самолёт и отправляем на посадку
                                if (plane.HasAction && plane.ActionTime < DateTime.Now)
                                {
                                    Zone zone      = Zone.BUS;
                                    bool isLanding = false;

                                    if (h1free)
                                    {
                                        zone      = Zone.HANGAR_1;
                                        isLanding = true;
                                        h1free    = false;
                                    }
                                    else if (h2free)
                                    {
                                        zone      = Zone.HANGAR_2;
                                        isLanding = true;
                                        h2free    = false;
                                    }
                                    if (isLanding)
                                    {
                                        string URL =
                                            String.Format("http://localhost:{0}/VisualizerService.svc/SpawnPlane?type={1}&id={2}&zone={3}&cargo={4}&passengerCount={5}&fuelCount={6}",
                                                          Ports.Visualizer, (int)Entity.PLANE, plane.Id, (int)Zone.PLANE_SPAWN, plane.CargoCount, plane.PassengerCount, plane.FuelCount);
                                        Util.MakeRequest(URL);
                                        URL = String.Format("http://localhost:{0}/VisualizerService.svc/Move?id={1}&zone={2}", Ports.Visualizer, plane.Id, (int)zone);
                                        Util.MakeRequest(URL);
                                        plane.State = EntityState.MOVING;
                                    }
                                }
                            }
                        }

                        // если самолёт уже сел
                        else if (plane.CurrentZone == Zone.HANGAR_1 || plane.CurrentZone == Zone.HANGAR_2)
                        {
                            // если самолёт закончил движение, то надо сказать службе наземного контроля о начале разгрузки/погрузки
                            if (plane.State == EntityState.FINISHED_TASK)
                            {
                                //TODO: начать погрузку/разгрузку самолёта
                                plane.State = EntityState.WAITING_FOR_COMMAND;
                            }
                            // если самолёт ждёт команды, то его уже погрузили, и пора улетать
                            else if (plane.State == EntityState.WAITING_FOR_COMMAND)
                            {
                                string URL = String.Format("http://localhost:{0}/VisualizerService.svc/Move?id={1}&zone={2}", Ports.Visualizer, plane.Id, (int)Zone.PLANE_SPAWN);
                                Util.MakeRequest(URL);
                                plane.State = EntityState.MOVING;
                            }
                            // если самолёт ждёт, то его ещё не загрузили
                            else if (plane.State == EntityState.STANDING_BY)
                            {
                                continue;
                            }
                        }

                        // остальные действия, такие как принятие пассажиров или отлёт, а также регистрация в службе наземного контроля, выполняются в веб-методах
                    }
                }
                Thread.Sleep(1000);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bombTexture = Content.Load<Texture2D>("Textures/Bomb");      // Load the texture
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font
            torus = new ModelObject();
            torus.Model = Content.Load<Model>("Models/Cube");
            torus.Texture = Content.Load<Texture2D>("Textures/Stripes");
            torus.Scale *= 5;

            mercury = new Planet();
            mercury.Parent = torus;
            mercury.RevolutionRate = MathHelper.PiOver2;
            mercury.Radius = 10;
            mercury.Scale *= 2;
            mercury.Model = torus.Model;
            mercury.Texture = torus.Texture;

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);
            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.Plane(99);
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            //plane.RotateX = 0.50f;
            plane.Position = new Vector3(0, -5, 0);

            UIElement background = new UIElement(Content.Load<Texture2D>("Textures/Jellyfish"),
                                    GraphicsDevice.Viewport.Bounds);
            ButtonGroup group = new ButtonGroup();
            group.Children.Add(new Button(Content.Load<Texture2D>("Textures/Stripes"),
                                new Rectangle(40,40,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Play",textFont));

            group.Children.Add(new Button(Content.Load<Texture2D>("Textures/Stripes"),
                                new Rectangle(40,80,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Information",textFont));

            group.Children.Add(new Button(Content.Load<Texture2D>("Textures/Stripes"),
                                new Rectangle(40,120,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Credits",textFont));

            group.Children.Add(new Button(null,
                                new Rectangle(40,160,200,25),
                                Content.Load<Texture2D>("Textures/Bomb"),
                                "Quit",textFont));
            group.Children[0].Clicked += StartNewGame;
            group.Children[3].Clicked += EndGame;
            background.Children.Add(group);

            elements[GameState.Start] = background;
            elements[GameState.Play] = new UIElement();
            elements[GameState.Pause] = background;

            effect = new BasicEffect(GraphicsDevice);
        }
Esempio n. 12
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bombTexture = Content.Load<Texture2D>("Textures/Bomb");      // Load the texture
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);

            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.Plane(99);
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            //plane.RotateX = 0.50f;
            plane.Position = new Vector3(0, -5, 0);

            cube = new AnimatedObject();
            cube.Model = Content.Load<Model>("Models/Dude/Dude");
            cube.Scale *= 0.25f;

            applause = Content.Load<SoundEffect>("Sounds/applause");
            currentSound = applause.CreateInstance();

            cube.StartAnimation("Take 001");
            effect = new BasicEffect(GraphicsDevice);
        }
Esempio n. 13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bombTexture = Content.Load<Texture2D>("Textures/Bomb");      // Load the texture
            textFont = Content.Load<SpriteFont>("Fonts/SegoeUI");    // Load the font
            torus = new ModelObject();
            torus.Model = Content.Load<Model>("Models/Cube");
            torus.Texture = Content.Load<Texture2D>("Textures/Stripes");
            torus.Scale *= 5;

            mercury = new Planet();
            mercury.Parent = torus;
            mercury.RevolutionRate = MathHelper.PiOver2;
            mercury.Radius = 10;
            mercury.Scale *= 2;
            mercury.Model = torus.Model;
            mercury.Texture = torus.Texture;

            // TODO: use this.Content to load your game content here
            camera = new Camera();
            camera.Position = new Vector3(0, 0, -20);
            camera.AspectRatio = GraphicsDevice.Viewport.AspectRatio;

            plane = new Common.Plane(99);
            plane.Texture = Content.Load<Texture2D>("Textures/Jellyfish");
            plane.Scale *= 50;
            //plane.RotateX = 0.50f;
            plane.Position = new Vector3(0, -5, 0);

            effect = new BasicEffect(GraphicsDevice);
        }
Esempio n. 14
0
        public static void HandlePlanes()
        {
            // все изменения списка самолётов проводятся ТОЛЬКО в основном цикле
            // веб-методы только меняют состояния уже существующих объектов
            int activePlanes = 0;

            while (true)
            {
                Thread.Sleep(1000);
                lock (Planes)
                {
//                    CommonUtil.Log(@"F:\Programming\CPP\Winsock\Aeroport\Plane\log"+ (iter++) +".txt", JsonConvert.SerializeObject(Planes));
                    // в данном цикле обрабатываются только те действия, которые инициируются самим самолётом
                    for (int i = 0; i < Planes.Count; i++)
                    {
                        Common.Plane plane = Planes[i];
                        // если самолёт находится в движении, то пропускаем его - ждём, пока закончит
                        if (plane.State == EntityState.MOVING)
                        {
                            continue;
                        }

                        // дальше действия зависят от текущей локации самолёта
                        // движение не рассматриваем

                        //если самолёт находится в воздухе
                        if (plane.CurrentZone == Zone.PLANE_SPAWN_1 || plane.CurrentZone == Zone.PLANE_SPAWN_2)
                        {
                            // если самолёт закончил движение, то его можно убрать и сгенерить новый
                            if (plane.State == EntityState.FINISHED_TASK)
                            {
                                RemovePlane(plane);
                                activePlanes--;
                            }
                            // если самолёт ждёт разрешения на посадку, то проверяем свободные полосы
                            else if (plane.State == EntityState.WAITING_FOR_COMMAND)
                            {
                                if (activePlanes < 2)
                                {
                                    activePlanes++;
                                    int landingDelay = RandomGen.Next(1, 5);
                                    plane.ActionTime = landingDelay;
                                    plane.HasAction  = true;
                                    plane.State      = EntityState.STANDING_BY;
                                }
                            }
                            // если самолёт ждёт своей очереди на посадку, то проверяем, пришло ли его время
                            else if (plane.State == EntityState.STANDING_BY)
                            {
                                // если время пришло, то спавним самолёт и отправляем на посадку
                                if (plane.HasAction)
                                {
                                    if (plane.ActionTime > 0)
                                    {
                                        plane.ActionTime--;
                                        continue;
                                    }
                                    Zone zone      = Zone.FUEL_STATION;
                                    bool isLanding = false;

                                    if (h1free)
                                    {
                                        zone = Zone.HANGAR_1;
                                        plane.CurrentZone = Zone.PLANE_SPAWN_1;
                                        isLanding         = true;
                                        h1free            = false;
                                    }
                                    else if (h2free)
                                    {
                                        zone = Zone.HANGAR_2;
                                        plane.CurrentZone = Zone.PLANE_SPAWN_2;
                                        isLanding         = true;
                                        h2free            = false;
                                    }
                                    if (isLanding)
                                    {
                                        SpawnPlane(plane);
                                        MovePlane(plane, zone);
                                    }
                                }
                            }
                        }

                        // если самолёт уже сел
                        else if (plane.CurrentZone == Zone.HANGAR_1 || plane.CurrentZone == Zone.HANGAR_2)
                        {
                            Zone despawnPoint = plane.CurrentZone == Zone.HANGAR_1
                                ? Zone.PLANE_SPAWN_1
                                : Zone.PLANE_SPAWN_2;
                            // если самолёт закончил движение, то надо сказать службе наземного контроля о начале разгрузки/погрузки
                            if (plane.State == EntityState.FINISHED_TASK)
                            {
                                //TODO: начать погрузку/разгрузку самолёта
                                StartPlaneMaintenance(plane);
                            }
                            // если самолёт ждёт команды, то его уже погрузили, и пора улетать
                            else if (plane.State == EntityState.WAITING_FOR_COMMAND)
                            {
                                MovePlane(plane, despawnPoint);
                            }
                            // если самолёт ждёт, то его ещё не загрузили
                            else if (plane.State == EntityState.STANDING_BY)
                            {
                                continue;
                            }
                        }

                        // остальные действия, такие как принятие пассажиров или отлёт, а также регистрация в службе наземного контроля, выполняются в веб-методах
                    }
                }
            }
        }