public bool OpenProject() { bool loadSuccessful = true; Microsoft.Win32.OpenFileDialog openDialog = new Microsoft.Win32.OpenFileDialog(); openDialog.DefaultExt = DEFAULT_EXT; openDialog.Filter = FILTER; bool? result = openDialog.ShowDialog(); bool isCorrectFileType = System.Text.RegularExpressions.Regex.IsMatch(openDialog.FileName, DEFAULT_EXT); if (result == true && isCorrectFileType) //User pressed OK and the extension is correct { loadSuccessful = true; projectFileName = openDialog.FileName; IFormatter format = new BinaryFormatter(); Stream stream = new FileStream(projectFileName, FileMode.Open, FileAccess.Read, FileShare.Read); ProjectData loadedProject = (ProjectData)format.Deserialize(stream); savedPrizeLevels = loadedProject.savedPrizeLevels; savedGameSetup = loadedProject.savedGameSetup; savedDivisions = loadedProject.savedDivisions; } else if (result == true && !isCorrectFileType) //User pressed OK, but the extension is incorrect { System.Windows.MessageBox.Show("The file must be of type " + DEFAULT_EXT); loadSuccessful = this.OpenProject(); } else if (result == false) //User pressed Cancel or closed the dialog box { loadSuccessful = false; } return loadSuccessful; }
public void testGetNumberOfDivisions() { DivisionsModel dm = new DivisionsModel(); for (int i = 0; i < numberOfTestRuns; i++) { DivisionModel div = new DivisionModel(); dm.addDivision(div); Assert.IsTrue(dm.getNumberOfDivisions() == i +1, "Number of divisions is wrong."); } }
public DivisionPanelUC() { InitializeComponent(); allottedPlayerPicks = 1; divisionsList = new DivisionsModel(); marginAmount = 10; divisionsScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; this.Loaded += new RoutedEventHandler(DivisionPanelUC_Loaded); divisionCounterLabel.Content = divisionsHolderPanel.Children.Count; }
public DivisionPanelUC() { InitializeComponent(); allottedPlayerPicks = 1; divisionsList = new DivisionsModel(); marginAmount = 10; divisionsScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; this.Loaded += new RoutedEventHandler(DivisionPanelUC_Loaded); divisionCounterLabel.Content = divisionsHolderPanel.Children.Count; divisionMaxPermutation.DataContext = divisionsList; }
public void SaveProject(GameSetupModel gsObject, PrizeLevels.PrizeLevels plsObject, DivisionsModel divisionsList) { if (isProjectSaved) { savedGameSetup = gsObject; savedPrizeLevels = plsObject; savedDivisions = divisionsList; IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(projectFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); formatter.Serialize(stream, this); stream.Close(); } else { SaveProjectAs(gsObject, plsObject, divisionsList); } }
public void testGetSetLossPermutations() { DivisionsModel dms = new DivisionsModel(); dms.LossMaxPermutations = 1000; Assert.IsTrue(dms.LossMaxPermutations == 1000); }
public void SaveProjectAs(GameSetupModel gsObject, PrizeLevels.PrizeLevels plsObject, DivisionsModel divisionsList) { Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog(); if (String.IsNullOrEmpty(projectFileName)) { dialog.FileName = "CollectionGameGeneratorProject" + DEFAULT_EXT; } else { dialog.FileName = projectFileName; } dialog.DefaultExt = DEFAULT_EXT; dialog.Filter = FILTER; bool? result = dialog.ShowDialog(); if (result == true) { projectFileName = dialog.FileName; isProjectSaved = true; SaveProject(gsObject, plsObject, divisionsList); } }
public void testBuildGameDataFiveDivisionsNinePicks() { GameSetupModel gs = new GameSetupModel(); gs.totalPicks = 9; PrizeLevel pl1 = new PrizeLevel(); pl1.isInstantWin = false; pl1.numCollections = 5; pl1.prizeValue = 100; PrizeLevel pl2 = new PrizeLevel(); pl2.isInstantWin = false; pl2.numCollections = 4; pl2.prizeValue = 50; PrizeLevel pl3 = new PrizeLevel(); pl3.isInstantWin = false; pl3.numCollections = 4; pl3.prizeValue = 25; PrizeLevel pl4 = new PrizeLevel(); pl4.isInstantWin = false; pl4.numCollections = 3; pl4.prizeValue = 10; PrizeLevel pl5 = new PrizeLevel(); pl5.isInstantWin = false; pl5.numCollections = 3; pl5.prizeValue = 5; PrizeLevels pls = new PrizeLevels(); pls.addPrizeLevel(pl1); pls.addPrizeLevel(pl2); pls.addPrizeLevel(pl3); pls.addPrizeLevel(pl4); pls.addPrizeLevel(pl5); DivisionModel dm1 = new DivisionModel(); dm1.addPrizeLevel(pl1); dm1.MaxPermutations = 1000; DivisionModel dm2 = new DivisionModel(); dm2.addPrizeLevel(pl1); dm2.addPrizeLevel(pl2); dm2.MaxPermutations = 1000; DivisionModel dm3 = new DivisionModel(); dm3.addPrizeLevel(pl1); dm3.addPrizeLevel(pl3); dm3.MaxPermutations = 1000; DivisionModel dm4 = new DivisionModel(); dm4.addPrizeLevel(pl2); dm4.addPrizeLevel(pl3); dm4.MaxPermutations = 1000; DivisionModel dm5 = new DivisionModel(); dm5.addPrizeLevel(pl4); dm5.addPrizeLevel(pl5); dm5.MaxPermutations = 1000; DivisionsModel dms = new DivisionsModel(); dms.addDivision(dm1); dms.addDivision(dm2); dms.addDivision(dm3); dms.addDivision(dm4); dms.addDivision(dm5); dms.LossMaxPermutations = 1000; FileGenerationService fgs = new FileGenerationService(); fgs.buildGameData(dms, pls, gs, "testBuildGameDataFiveDivisionsNinePicks"); }
public void testBuildGameDataThreeDivisonsFourPicksWithLoss() { //Custom input for a game GameSetupModel gs = new GameSetupModel(); gs.totalPicks = 4; PrizeLevel pl1 = new PrizeLevel(); pl1.isInstantWin = false; pl1.numCollections = 3; pl1.prizeValue = 100; PrizeLevel pl2 = new PrizeLevel(); pl2.isInstantWin = false; pl2.numCollections = 2; pl2.prizeValue = 50; PrizeLevel pl3 = new PrizeLevel(); pl3.isInstantWin = false; pl3.numCollections = 2; pl3.prizeValue = 25; PrizeLevels pls = new PrizeLevels(); pls.addPrizeLevel(pl1); pls.addPrizeLevel(pl2); pls.addPrizeLevel(pl3); DivisionModel dm1 = new DivisionModel(); dm1.addPrizeLevel(pl1); dm1.MaxPermutations = 1000; DivisionModel dm2 = new DivisionModel(); dm2.addPrizeLevel(pl2); dm2.MaxPermutations = 1000; DivisionModel dm3 = new DivisionModel(); dm3.addPrizeLevel(pl2); dm3.addPrizeLevel(pl3); dm3.MaxPermutations = 1000; DivisionModel dm4 = new DivisionModel(); dm4.MaxPermutations = 1000; DivisionsModel dms = new DivisionsModel(); dms.addDivision(dm1); dms.addDivision(dm2); dms.addDivision(dm3); dms.addDivision(dm4); dms.LossMaxPermutations = 1000; //File Generator FileGenerationService fgs = new FileGenerationService(); fgs.buildGameData(dms, pls, gs, "testBuildGameDataThreeDivisonsFourPicksWithLoss"); }
public void testBuildGameDataMaxDivison() { GameSetupModel gs = new GameSetupModel(); gs.totalPicks = 20; int numPrizeLevels = 12; PrizeLevel[] prizes = new PrizeLevel[numPrizeLevels]; PrizeLevels pls = new PrizeLevels(); for (int i = 0; i < numPrizeLevels; i++) { prizes[i] = new PrizeLevel(); prizes[i].isInstantWin = false; prizes[i].numCollections = i + 1; prizes[i].prizeValue = 100 * i; pls.addPrizeLevel(prizes[i]); } int numberOfDivions = 30; DivisionModel[] divisions = new DivisionModel[numberOfDivions]; DivisionsModel dms = new DivisionsModel(); dms.LossMaxPermutations = 30000; Random rand = new Random(); for (int i = 0; i < numberOfDivions; i++) { divisions[i] = new DivisionModel(); divisions[i].addPrizeLevel(prizes[rand.Next(0, 12)]); divisions[i].MaxPermutations = 30000; dms.addDivision(divisions[i]); } FileGenerationService fgs = new FileGenerationService(); fgs.buildGameData(dms, pls, gs, "MaxTest"); }