Example #1
0
        /// <summary>
        /// Create a new Rack
        /// </summary>
        /// <param name="x">x-position</param>
        /// <param name="y">y-position</param>
        /// <param name="z">z-position</param>
        /// <returns>Returns the rack that was created</returns>
        private Racks CreateRack(Node node)
        {
            Racks rack = new Racks(this, "rack", node.x, 2, node.z, -0.05, -1.42, 0);

            rack.currentNode = node;
            worldObjects.Add(rack);
            return(rack);
        }
Example #2
0
        /// <summary>
        /// Adds a new task for the robots
        /// </summary>
        /// <param name="rack">The rack to be added</param>
        /// <param name="typeNode">The final node type (leave blank to get the opposite type of the current node)</param>
        public void AddTask(Racks rack, string typeNode = "")
        {
            while (rack.moving)
            {
                Thread.Sleep(1000); // Pause the program until the rack has arrived
            }

            // Create a new task
            Task newTask = new Task();

            newTask.firstDestination = rack.currentNode;
            newTask.finalDestination = World.grid.GetAvailableNode(rack.currentNode, typeNode); // Find a node where the rack can be placed
            newTask.getRack          = rack;

            // Occupy the final destination so other robots won't go there
            newTask.firstDestination.occupied = false;
            newTask.finalDestination.occupied = true;

            Tasks.Add(newTask);
        }
Example #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);
            }
        }
Example #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);
        }
Example #5
0
 /// <summary>
 /// Lets the rack move along with the robot.
 /// </summary>
 /// <param name="rack">Racks object</param>
 /// <param name="robot">Robots object</param>
 public void MovingRack(Racks rack, Robots robot)
 {
     rack.x = robot.x;
     rack.z = robot.z;
 }
Example #6
0
        /// <summary>
        /// Prompts the user to order products
        /// </summary>
        public void PromptUser()
        {
            string productName = "";
            int    amount      = 0;

            Console.WriteLine("Please enter your order.");
            Console.WriteLine("{product name} {amount}");

            string input = Console.ReadLine(); // User input

            string[] param = input.Split(' ');

            // Check if the input is valid
            if (param.Count() >= 1)
            {
                productName = param[0];
            }

            if (param.Count() == 2)
            {
                int.TryParse(param[1], out amount);
            }

            if (param.Count() > 2 || productName == "")
            {
                Console.WriteLine("Something went wrong with your input");
                return;
            }

            Product result = SearchProduct(productName);       // Search the entered product
            Racks   rack   = SearchRackByProduct(productName); // Search the rack

            if (rack != null)
            {
                if (amount <= result.stock)
                {
                    // Create a copy of the product to be shipped
                    Product productToShip = new Product();
                    productToShip = productToShip.Clone(result);

                    // Remove stock from the copy and add to shipments
                    productToShip.RemoveStock(productToShip.stock - amount);
                    AddOrderOrShipment(Shipments, productToShip);

                    // Start new tread to add the task
                    Console.WriteLine("Ordered {0} of {1}", amount, productName);
                    Thread inventoryThread = new Thread(() => AddTask(rack, "cargoNode"));
                    inventoryThread.Start();
                }
                else
                {
                    Console.WriteLine("Your order is too large or too small.");
                }
            }
            else if (result != null && param.Count() == 2)
            {
                Console.WriteLine("Rack couldn't be found, try again later.");
            }

            if (param.Count() == 1 && productName == "list")
            {
                ShowStock();
            }
            else if (result == null)
            {
                bool correct = false;
                while (!correct)
                {
                    Console.WriteLine("{0}, was not found. Do you want to add this item to the invetory? (Y/N)", productName);
                    string AddProduct = Console.ReadLine();
                    if (AddProduct.ToLower().ToString() == "y")
                    {
                        this.AddProduct(productName);
                        correct = true;
                    }
                    else if (AddProduct.ToLower().ToString() == "n")
                    {
                        correct = true;
                    }
                }
            }
        }
Example #7
0
 /// <summary>
 /// Removes the rack from the list Racks.
 /// </summary>
 /// <param name="rack">Rack to be deleted</param>
 public void RemoveRack(Racks rack)
 {
     Racks.Remove(rack);
 }
Example #8
0
 /// <summary>
 /// Adds the object rack to the list Racks.
 /// </summary>
 /// <param name="rack">Rack to be added</param>
 public void AddRack(Racks rack)
 {
     Racks.Add(rack);
 }