private void RefreshStateAndUpdateDisplays() { int k; double totd; instance.CalculateObjectives(out k, out totd); trucksUsed.Value = k; distanceTraveled.Value = totd; if (instance.CheckFeasibility()) { ofBKS.Value = (int)((2 * instance.BKS_val - totd) / instance.BKS_val * 100.0); ofBKSDisplayNA.IsVisible = false; ofBKSDisplay.IsVisible = true; if (!optimalLoaded && (currentInstanceMetadata.personalBest_k == null || k < currentInstanceMetadata.personalBest_k || (k == (int)currentInstanceMetadata.personalBest_k && totd < currentInstanceMetadata.personalBestSol))) { currentInstanceMetadata.Stars = ShowNewPersonalBest(k, totd); currentInstanceMetadata.personalBest_k = k; currentInstanceMetadata.personalBestSol = totd; if (currentInstanceMetadata.Stars > 0) { int ciInx = problemInstanceMetadata.IndexOf(currentInstanceMetadata); if (ciInx + 1 < problemInstanceMetadata.Count) { problemInstanceMetadata[ciInx + 1].Locked = false; } } VRPProblemSelector.SavePlayerInstanceDataToFile(problemInstanceMetadata, @"Content\PlayerData.txt"); } } else { ofBKS.Value = 99; ofBKSDisplayNA.IsVisible = true; ofBKSDisplay.IsVisible = false; } UpdateTruckFillRatios(instance.routeFillRatios); UpdateDisplayIconPosition(trucksDisplay); UpdateDisplayIconPosition(distanceDisplay); UpdateDisplayIconPosition(ofBKSDisplay); }
public override void Begin() { TouchPanel.Listen(ButtonState.Down, (tp) => MessageDisplay.Add("liikkuu"), "Liikuttaa pelaajaa"); //SetWindowSize(1050, 590); // Contols and events Level.Background.Color = BackgroundColor; Mouse.IsCursorVisible = true; PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); Keyboard.Listen(Key.N, ButtonState.Released, ToggleNodeLables, "Näytä numerointi"); Keyboard.Listen(Key.L, ButtonState.Released, ToggleNodeLables, "Näytä numerointi"); Keyboard.Listen(Key.D, ButtonState.Released, ToggleDemandLabels, "Näytä tilausten koot"); Keyboard.Listen(Key.S, ButtonState.Released, ShowOptimalSolution, "Näytä ratkaisu"); // Select the problem to play problemMenu = new VRPProblemSelector(this); problemInstanceMetadata = VRPProblemSelector.LoadInstanceDataFromFile(@"Content\problemdata.txt"); if (UNLOCK_ALL) { problemInstanceMetadata.ForEach(i => i.Locked = false); } VRPProblemSelector.LoadPlayerInstanceDataFromFile(@"Content\playerdata.txt", problemInstanceMetadata); //Mouse.Listen(MouseButton.Left, ButtonState.Pressed, MenuMousePressed, "Valitse kenttä"); problemMenu.ViewSetSelect(problemInstanceMetadata, OnSetSelected); //StartGame(@"C:\Users\juherask\Dissertation\Phases\Tuning\Benchmarks\VRPLIB\E\E-n13-k4.vrp"); Timer blinkInfeasible = new Timer(); blinkInfeasible.Interval = 0.33; blinkInfeasible.TimesLimited = false; blinkInfeasible.Timeout += BlinkBlinkingObjects; blinkInfeasible.Start(); }
public void ViewProblemSelect(List <ProblemInstance> instances, ProblemSelectedHandler handler, int perRow = 6) { var selh = Game.Screen.Height / VRPGame.SCREEN_MARGIN_WIDHT_RATIO; // int perRow = Math.Max(1,instances.Count/MAX_ROWS); double btnSize = (Game.Screen.Width - SPACING_BETWEEN_BTNS * (perRow + 3)) / perRow; var vl = new VerticalLayout(); vl.Spacing = SPACING_BETWEEN_BTNS; Widget vgrid = new Widget(vl); for (int i = 0; i < MAX_ROWS && i * perRow < instances.Count; i++) { var hl = new HorizontalLayout(); hl.Spacing = SPACING_BETWEEN_BTNS; Widget hgrid = new Widget(hl); for (int j = i * perRow; j < (i + 1) * perRow && j < instances.Count; j++) { var probI = instances[j]; PushButton selectThisProblemBtn = VRPProblemSelector.CreateInstanceButton(btnSize, probI.ProblemName, probI.Stars, probI.Locked); if (!probI.Locked) { selectThisProblemBtn.Clicked += () => handler(probI); selectThisProblemBtn.Clicked += () => game.Remove(vgrid); } hgrid.Add(selectThisProblemBtn); } vgrid.Add(hgrid); } game.Add(vgrid, -1); }
int ShowNewPersonalBest(int new_k, double new_totd) { string text = ""; int stars = 0; if (new_k <= instance.BKS_k) { if (new_totd <= instance.BKS_val * 1.05) { stars = 3; text += "Erinomaisesti reititetty."; if (new_totd == instance.BKS_val) { text += " Itseasiassa löysit optimiratkaisun, eli parhaan mahdollisen reitityksen."; } } else if (new_totd <= instance.BKS_val * 1.20) { stars = 2; text += "Hyvin reititetty. Reittejä voi kuitenkin vielä parantaa. Keksitkö miten?"; } else { stars = 1; text += "Kelpo reititys. Pystytkö muokkaamaan reitit lyhyemmiksi?"; } } else if (new_k - 1 == instance.BKS_k) { if (new_totd < instance.BKS_val * 1.20) { stars = 2; text += "Hyvin reititetty. Kujetukset voisi vielä silti tehdä pienemmällä määrällä autoja. Keksitkö miten?"; } else { stars = 1; text += "Kelpo reititys. Pystyt varmasti kuitenkin parantamaan sitä!"; } } if (stars > 0) { Widget levelCompleteWindow = new Widget(Screen.Width / 4, Screen.Height / 3); levelCompleteWindow.Layout = new VerticalLayout(); var instanceButton = VRPProblemSelector.CreateInstanceButton(Screen.Width / 4, currentInstanceMetadata.ProblemName, stars); levelCompleteWindow.Add(instanceButton); var infotext = new Label(text); infotext.SizeMode = TextSizeMode.Wrapped; levelCompleteWindow.Add(infotext); Widget continueOrNext = new Widget(new HorizontalLayout()); var continueBtn = new PushButton("Jatka yrittämistä"); continueBtn.Clicked += () => Remove(levelCompleteWindow); continueOrNext.Add(continueBtn); var nextBtn = new PushButton("Seuraava tehtävä"); nextBtn.Clicked += () => ChooseNextLevel(); continueOrNext.Add(nextBtn); levelCompleteWindow.Add(continueOrNext); Add(levelCompleteWindow, -1); StarXplosion(1, stars, instanceButton); // emulate mb release Timer.SingleShot(0.1, () => MouseBtnGoesUp()); } return(stars); }