Example #1
0
        public static Car CreateRightPumpBottomTour()
        {
            var car  = CreateTopCar();
            var pump = new GasPump();

            Canvas.SetLeft(pump, GasPump.RightX);
            Canvas.SetTop(pump, 275);
            car.GasPump = pump;

            CreatStoryBoardToPump(
                car,
                timeSetTo1,
                BottomY,
                PumpBottomY + turnOffset,
                PumpBottomY,
                RightX2,
                RightX0);

            CreatStoryBoardFromPump(
                car,
                timeSetFrom1,
                PumpBottomY,
                PumpBottomY - turnOffset,
                TopY,
                RightX2,
                RightX0);

            return(car);
        }
Example #2
0
 public MainPage()
 {
     gasp  = new GasPump();
     Model = new GaspumpViewModel();
     InitializeComponent();
     MainFrame.Content = new ShopPage();
 }
Example #3
0
        /// <summary>
        /// Creates the left pump bottom tour.
        /// </summary>
        /// <returns></returns>
        public static Car CreateLeftPumpBottomTour()
        {
            var car  = CreateBottomCar();
            var pump = new GasPump();

            Canvas.SetLeft(pump, GasPump.LeftX);
            Canvas.SetTop(pump, 240);
            car.GasPump = pump;

            CreatStoryBoardToPump(
                car,
                timeSetTo2,
                TopY,
                PumpBottomY - turnOffset,
                PumpBottomY,
                LeftX0,
                LeftX2);

            CreatStoryBoardFromPump(
                car,
                timeSetFrom2,
                PumpBottomY,
                PumpBottomY + turnOffset,
                BottomY,
                LeftX0,
                LeftX2);

            return(car);
        }
        public ActionResult Checkout(int gasPumpIndex)
        {
            // get selected gas pump
            GasPump gasPump = Context.GetGasStation().GetGasPumps()[gasPumpIndex];

            // call 'LockFueling'
            gasPump.LockFueling();

            return(RedirectToAction("Index", new { gasPumpIndex }));
        }
Example #5
0
        public static void Main()
        {
            var petrolPumpsCount = int.Parse(Console.ReadLine());
            var pumps            = new Queue <GasPump>();

            for (int i = 0; i < petrolPumpsCount; i++)
            {
                var tourInfo = Console
                               .ReadLine()
                               .Split()
                               .Select(int.Parse)
                               .ToArray();

                var amountOfGas    = tourInfo[0];
                var distanceToNext = tourInfo[1];

                GasPump pump = new GasPump(amountOfGas, distanceToNext, i);

                pumps.Enqueue(pump);
            }

            GasPump starterPump  = null;
            bool    completeTour = false;

            while (pumps.Count > 0)
            {
                GasPump currentPump = pumps.Dequeue();
                pumps.Enqueue(currentPump);

                starterPump = currentPump;
                var gasInTank = currentPump.amountOfGas;

                while (gasInTank >= currentPump.distanceToNext)
                {
                    gasInTank -= currentPump.distanceToNext;

                    currentPump = pumps.Dequeue();
                    pumps.Enqueue(currentPump);

                    if (currentPump == starterPump)
                    {
                        completeTour = true;
                        break;
                    }

                    gasInTank += currentPump.amountOfGas;
                }

                if (completeTour)
                {
                    Console.WriteLine(currentPump.index);
                    break;
                }
            }
        }
        public ActionResult ReleaseGasPump(int gasPumpIndex, int cashRegisterIndex)
        {
            //
            GasPump      gasPump      = Context.GetGasStation().GetGasPumps()[gasPumpIndex];
            CashRegister cashRegister = Context.GetGasStation().GetCashRegisters()[cashRegisterIndex];

            gasPump.Clear();
            cashRegister.Clear();

            return(RedirectToAction("Index", new { gasPumpIndex }));
        }
        public ActionResult Pay(int gasPumpIndex, int cashRegisterIndex)
        {
            // get selected gas pump and cash register
            GasPump      gasPump      = Context.GetGasStation().GetGasPumps()[gasPumpIndex];
            CashRegister cashRegister = Context.GetGasStation().GetCashRegisters()[cashRegisterIndex];

            // call 'AcceptInput' on selected cash register
            cashRegister.AcceptInput(gasPump.GetPaymentAmount());

            return(RedirectToAction("Index", new { gasPumpIndex }));
        }
        public ActionResult Refuel(int gasPumpIndex, int tapIndex, float liter)
        {
            // get selected gas pump
            GasPump gasPump = Context.GetGasStation().GetGasPumps()[gasPumpIndex];

            // get tap and call 'Fuel'
            Tap tap = gasPump.GetTaps()[tapIndex];

            gasPump.Fuel(tap, liter);

            return(RedirectToAction("Index", new { gasPumpIndex }));
        }
        public ActionResult SelectTap(int gasPumpIndex, int tapIndex)
        {
            // get selected gas pump
            GasPump gasPump = Context.GetGasStation().GetGasPumps()[gasPumpIndex];

            // get requested tap and call 'SelectTap'
            Tap tap = gasPump.GetTaps()[tapIndex];

            gasPump.SelectTap(tap);

            return(RedirectToAction("Index", new { gasPumpIndex }));
        }
Example #10
0
        private void CreateObject(TmxObject obj, Rectangle source, TmxTileset tileset, Texture2D tilesetTexture)
        {
            var    random        = new Random();
            var    type          = tileset.Tiles[obj.Tile.Gid - tileset.FirstGid].Type;
            var    rotation      = MathHelper.ToRadians((float)obj.Rotation);
            var    spawnPosition = GetObjectPosition(obj, source);
            Entity entity;

            switch (type)
            {
            case "Car":
                entity = new Car(this, tilesetTexture, (int)obj.Width, (int)obj.Height, spawnPosition,
                                 rotation, source);
                break;

            case "Enemy_Spawn":
                entity = new Enemy(tilesetTexture, spawnPosition, (int)obj.Width, (int)obj.Height, this,
                                   rotation, source);
                break;

            case "Dungeon_Entrance":
                entity = new DungeonEntrance(new ShooterScreen(), screenManager, tilesetTexture, (int)obj.Width,
                                             (int)obj.Height, spawnPosition, rotation, source);
                break;

            case "Collectable":
                entity = new Collectable(tilesetTexture, spawnPosition, (int)obj.Width, (int)obj.Height, rotation, source);
                break;

            case "Ammo":
                var randomBulletType = (BulletType)random.Next(Enum.GetNames(typeof(BulletType)).Length);
                entity = new AmmoPack(randomBulletType, random.Next(15, 30), tilesetTexture, spawnPosition,
                                      (int)obj.Width, (int)obj.Height, rotation, source);
                break;

            case "Health":
                entity = new HealthPack(random.Next(15, 30), tilesetTexture, spawnPosition, (int)obj.Width,
                                        (int)obj.Height, rotation, source);
                break;

            case "Gas":
                entity = new GasPump(tilesetTexture, (int)obj.Width, (int)obj.Height, spawnPosition, rotation, source);
                break;

            default:
                entity = new Entity(tilesetTexture, (int)obj.Width, (int)obj.Height, spawnPosition, rotation,
                                    source);
                break;
            }

            EntityManager.Instance.AddEntity(entity);
        }
Example #11
0
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());

            Queue <GasPump> pumpsQ     = new Queue <GasPump>();
            List <GasPump>  pumpsTestL = new List <GasPump>();

            // create the Pump objects from input and add them to queue.
            for (int i = 0; i < n; i++)
            {
                string[] pumpInfo       = Console.ReadLine().Split();
                int      distanceToNext = Int32.Parse(pumpInfo[1]);
                int      amountOfGas    = Int32.Parse(pumpInfo[0]);

                GasPump pump = new GasPump(distanceToNext, amountOfGas, i);
                pumpsQ.Enqueue(pump);
            }

            bool    completeJourney = false;
            GasPump starterPump     = null;

            while (completeJourney == false)
            {
                starterPump = pumpsQ.Dequeue();                                       //set starting point
                pumpsQ.Enqueue(starterPump);                                          //encue starting pump to main queue in case it does not work out
                pumpsTestL = pumpsQ.ToList();                                         //convert the current queue to list for inner cycle

                GasPump currentPump = starterPump;                                    // set the current to the starting point

                int gasInTank = starterPump.amountOfGas - starterPump.distanceToNext; // calculate ammount of gas after travel to second pump

                if (gasInTank < 0)                                                    // if journey cannot be even started, start the check from the next station.
                {
                    continue;
                }

                for (int i = 0; i < n; i++) // run cycle for the remaining number of pumps on the generated list
                {
                    if (gasInTank < 0)      // if journey cannot be completed, start the check from the next station.
                    {
                        break;
                    }

                    currentPump = pumpsTestL[i];//get next pump
                    gasInTank  += currentPump.amountOfGas - currentPump.amountOfGas;
                }

                completeJourney = true;
            }

            Console.WriteLine(starterPump.indexOfPump);
        }
Example #12
0
    public static void Main()
    {
        var n     = int.Parse(Console.ReadLine());
        var pumps = new Queue <GasPump>();

        for (int i = 0; i < n; i++)
        {
            var pumpInfo       = Console.ReadLine().Split();
            var distanceToNext = int.Parse(pumpInfo[1]);
            var amounthOfGas   = int.Parse(pumpInfo[0]);

            GasPump pump = new GasPump(distanceToNext, amounthOfGas, i);
            pumps.Enqueue(pump);
        }

        GasPump starterPump    = null;
        bool    completeJorney = false;

        while (true)
        {
            var currentPump = pumps.Dequeue();
            pumps.Enqueue(currentPump);
            starterPump = currentPump;
            var gasInTank = currentPump.AmounthOfGas;

            while (gasInTank >= currentPump.DistanceToNext)
            {
                gasInTank -= currentPump.DistanceToNext;

                currentPump = pumps.Dequeue();
                pumps.Enqueue(currentPump);

                if (currentPump == starterPump)
                {
                    completeJorney = true;
                    break;
                }
                gasInTank += currentPump.AmounthOfGas;
            }
            if (completeJorney)
            {
                Console.WriteLine(starterPump.IndexOfPump);
                break;
            }
        }
    }
        /// <summary>
        /// Schliesst die "Behandlung" von der aktuell ausgewählten Zapfsäule ab.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnAbschliessen_Click(object sender, RoutedEventArgs e)
        {
            GasPump selectedGasPump = (GasPump)GasPumpComboBox.SelectedItem;
            int     result          = Context.FinishPayment(selectedGasPump);

            if (result == 0)
            {
                _tbxAnzeige.Text = "";
            }
            else if (result == 1)
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Sind Sie sicher, dass Sie die Zahlung beenden wollen? Es stehen noch Rechnungen offen.", "Zahlung beednen?", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (MessageBoxResult.OK == messageBoxResult)
                {
                    Context.FinishPayment(selectedGasPump, false);
                    _tbxAnzeige.Text = "";
                }
            }
        }
        /// <summary>
        /// Schliesst die Zahlung ab, sofern genug Geld eingeworfen wurde.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnFertig_Click(object sender, RoutedEventArgs e)
        {
            GasPump selectedGasPump = (GasPump)GasPumpComboBox.SelectedItem;

            int[] outputCoins = new int[1];
            try
            {
                outputCoins = Context.FinishInput(selectedGasPump);
                if (outputCoins[0] == -1)
                {
                    _tbxAnzeige.Text += $"\r\nEs wurde noch zu wenig Geld eingeworfen. Es fehlen noch {selectedGasPump.ToPayValue - decimal.Parse(Context.GetValueInput().ToString()) / 100} Franken.";
                }
                else
                {
                    _tbxAnzeige.Text += "\r\nAusgabe:\r\n";
                    RenderNumberOfCoins(outputCoins);
                    DisableButtons();

                    IReceipt receipt = Context.CreateReceipt(selectedGasPump);
                    selectedGasPump.ToPayValue = 0;
                    ReceiptDisplay receiptDisplay = new ReceiptDisplay();
                    receiptDisplay.Context = receipt;
                    receiptDisplay.Show();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.StartsWith("Es kann leider kein Rückgeld gegeben werden."))
                {
                    MessageService.AddWarningMessage("Fehler", $"{ex.Message}\r\n{ex.Source}\r\n{ex.StackTrace}");
                }
                else
                {
                    MessageService.AddErrorMessage("Fehler", ex.Message);
                }
                return;
            }
        }
Example #15
0
 /// <summary>
 /// Neue Zapfsäulen hinzufügen
 /// </summary>
 /// <param name="gasPump"></param>
 public void AddGasPump(GasPump gasPump)
 {
     gasPumps.Add(gasPump);
 }
Example #16
0
        /// <summary>
        /// Scannt alle json und füllt die Daten in Objekte ab
        /// </summary>
        private void GetDataAsJson()
        {
            try
            {
                //GASPUMP
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\gasPumpConfig.json"))
                {
                    string fileString  = sr.ReadToEnd();
                    JToken gasPumpJson = JObject.Parse(fileString)["gasPumps"];

                    foreach (JToken gasPumpToken in gasPumpJson)
                    {
                        GasPump gasPump = new GasPump(Convert.ToInt32(gasPumpToken["GasPumpNumber"]));
                        gasPump.Status = (GasPumpStatus)Convert.ToInt32(gasPumpToken["Status"]);
                        gasPumps.Add(gasPump);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr gasPumpConfig.json", "GasPump kann nicht ausgelesen werden");
            }

            try
            {
                //TANK
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\tankConfig.json"))
                {
                    string fileString = sr.ReadToEnd();
                    JToken tankJson   = JObject.Parse(fileString)["tanks"];

                    foreach (JToken tankToken in tankJson)
                    {
                        Tank tank = new Tank();
                        tank.Number         = Convert.ToInt32(tankToken["Number"]);
                        tank.Name           = tankToken["Name"].ToString();
                        tank.FuelName       = tankToken["FuelName"].ToString();
                        tank.AvailibleLiter = float.Parse(tankToken["AvailibleLiter"].ToString());
                        tank.VolumeLiter    = float.Parse(tankToken["VolumeLiter"].ToString());
                        tank.MinAmount      = float.Parse(tankToken["MinAmount"].ToString());
                        tanks.Add(tank);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr tankConfig.json", "Tank kann nicht ausgelesen werden");
            }

            try
            {
                //FUEL
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\fuelConfig.json"))
                {
                    string fileString = sr.ReadToEnd();
                    JToken fuelJson   = JObject.Parse(fileString)["fuels"];

                    foreach (JToken fuelToken in fuelJson)
                    {
                        Fuel fuel = new Fuel();
                        fuel.Name          = fuelToken["Name"].ToString();
                        fuel.PricePerLiter = Convert.ToDecimal(fuelToken["PricePerLiter"]);
                        fuels.Add(fuel);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr fuelConfig.json", "Fuel kann nicht ausgelesen werden");
            }

            try
            {
                //RECEIPT
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\receiptConfig.json"))
                {
                    string fileString  = sr.ReadToEnd();
                    JToken receiptJson = JObject.Parse(fileString)["receipts"];

                    foreach (JToken receiptToken in receiptJson)
                    {
                        Receipt receipt = new Receipt();
                        receipt.Id           = Convert.ToInt32(receiptToken["Id"]);
                        receipt.Date         = DateTime.Parse(receiptToken["Date"].ToString());
                        receipt.RelatedFuel  = GetFuelByName(receiptToken["RelatedFuel"].ToString());
                        receipt.RelatedLiter = float.Parse(receiptToken["RelatedLiter"].ToString());
                        receipt.Sum          = Convert.ToDecimal(receiptToken["Sum"].ToString());
                        receipts.Add(receipt);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr receiptConfig.json", "Receipt kann nicht ausgelesen werden");
            }

            try
            {
                //Coin
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\coinConfig.json"))
                {
                    string fileString = sr.ReadToEnd();
                    JToken coinJson   = JObject.Parse(fileString)["coins"];

                    foreach (JToken coinToken in coinJson)
                    {
                        Coin coin = new Coin(Convert.ToInt32(coinToken));
                        coins.Add(coin);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr coinConfig.json", "Coin kann nicht ausgelesen werden");
            }
        }