Esempio n. 1
0
        /// <summary>
        /// Create a new spaceship
        /// </summary>
        /// <param name="x">x-position</param>
        /// <param name="y">y-position</param>
        /// <param name="z">z-position</param>
        /// <returns>Returns the spaceship that was created</returns>
        private Spaceships CreateSpaceShip(double x, double y, double z)
        {
            Spaceships ship = new Spaceships(this, "spaceship", x, y, z, 0, 0, 0);

            ship.reset();
            worldObjects.Add(ship);
            return(ship);
        }
Esempio n. 2
0
        /// <summary>
        /// Spaceship receives the shipment
        /// </summary>
        /// <param name="spaceship"></param>
        private void ReceiveShipment(Spaceships spaceship)
        {
            Task task = null;

            for (int i = 0; i <= Inventory.shipments.Count() - 1; i++) // Each shipment
            {
                for (int j = 0; j <= Inventory.racks.Count() - 1; j++) // Each rack
                {
                    if (Inventory.racks[j].currentNode.type == "cargoNode" && !Inventory.racks[j].moving && !Inventory.orders.Contains(Inventory.shipments[i]))
                    {
                        for (int k = 0; k <= Inventory.racks[j].contains.Count() - 1; k++) // Each product in each rack
                        {
                            if (Inventory.racks[j].contains[k].id == Inventory.shipments[i].id)
                            {
                                spaceship.AddCargo(Inventory.shipments[i]);
                                task = Inventory.racks[j].RemoveStock(Inventory.racks[j].contains[k], Inventory.shipments[i].stock);
                                Inventory.shipments.Remove(Inventory.shipments[i]);

                                if (task != null)
                                {
                                    Inventory.Tasks.Add(task);
                                }

                                if (Inventory.shipments.Count() == 0)
                                {
                                    return;
                                }
                            }
                        }

                        // Delete the rack
                        if (Inventory.racks[j].contains.Count() == 0)
                        {
                            Inventory.racks[j].currentNode.occupied = false;
                            Inventory.racks[j].attr = "deleted";
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Checks if the spaceship is in the right coordinates by calling the methode spaceship.checkCooridinates which returns a true or false
        /// if true than it counts count up to 10 (This because otherwise the z coordinates whill be different) if false nothing will be done. If
        /// count is 10 or bigger than it will create racks if the node is not occupied.
        /// </summary>
        /// <param name="spaceship">Receives the object spaceship</param>
        /// <returns>boolean</returns>
        private bool ReceiveCargo(Spaceships spaceship)
        {
            if (spaceship.checkCoordinates() && count < 11)
            {
                count++;
            }

            if (10 <= count)
            {
                while (Inventory.orders.Count != 0)
                {
                    for (int i = 3; i < 8; i++)
                    {
                        if (!grid.GetNodes[i].occupied)
                        {
                            // Create the rack
                            rack = CreateRack(grid.GetNodes[i]);
                            Inventory.AddRack(rack);

                            // Set node to occupied
                            grid.GetNodes[i].occupied = true;

                            // Add products to the rack
                            rack.AddProduct(Inventory.orders.First());
                            Inventory.orders.Remove(Inventory.orders.First());
                            Inventory.AddTask(rack);
                            break;
                        }
                    }
                }
                count = 0;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        public bool Update(int tick)
        {
            for (int i = 0; i < worldObjects.Count; i++)
            {
                Model3D u = worldObjects[i];

                if (u is IUpdatable)
                {
                    bool needsCommand = ((IUpdatable)u).Update(tick);

                    if (needsCommand)
                    {
                        if (u is Robots)
                        {
                            Robots robot = (Robots)u;
                            robot.Update(tick);
                        }
                        else if (u is Spaceships)
                        {
                            Spaceships spaceship = (Spaceships)u;
                            spaceship.needsUpdate = true;

                            // Check if the spaceship is above the building and shipments is not empty
                            if (Inventory.shipments.Count() > 0 && (spaceship.z <= 8 && spaceship.z >= -8))
                            {
                                ReceiveShipment(spaceship);
                            }

                            // Check if the warehouse needs to be restocked after the spaceship passed the building
                            if (spaceship.z < -8)
                            {
                                Inventory.CheckStock();
                            }

                            // Check if the warehouse has orders
                            if (Inventory.orders.Count() > 0)
                            {
                                checkCoordinateShip = ReceiveCargo(spaceship);
                            }

                            // Move the spaceship if the spaceship has any type of orders or has already begun moving
                            if ((Inventory.orders.Count() > 0 || Inventory.shipments.Count() > 0) || (spaceship.z > -140 ^ spaceship.z == 125))
                            {
                                spaceship.moveSpaceship();
                            }

                            // If the spaceship has almost reached his destination, you receive your delivery
                            if (spaceship.z == -139 && spaceship.cargo.Count() > 0)
                            {
                                spaceship.cargo.ForEach(x =>
                                                        Console.WriteLine("{0} of {1} was delivered to you", x.stock, x.name));

                                spaceship.cargo.Clear();
                            }
                        }
                        else if (u is Racks)
                        {
                            Racks rack = (Racks)u;
                            rack.moveRack();

                            if (rack.attr == "deleted")
                            {
                                worldObjects.Remove(rack);
                                Inventory.RemoveRack(rack);
                            }
                        }

                        else if (u is Doors)
                        {
                            Doors door = (Doors)u;
                            door.Update(tick);
                        }

                        else if (u is Model3D)
                        {
                            Model3D model = (Model3D)u;
                            //If model type is light then call the methode move of light.
                            if (model.type == "light")
                            {
                                model.Move(model.x, model.y, model.z);
                            }

                            //Calls the methode moveEarth and gives model along with it.
                            moveEarth(model);
                        }

                        SendCommandToObservers(new UpdateModel3DCommand(u));
                    }
                }
            }
            return(true);
        }