Example #1
0
        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;
        }
Example #2
0
 public void TestToggleIsNearWin()
 {
     GameSetupModel gsm = new GameSetupModel();
     gsm.toggleNearWin();
     Assert.IsTrue(gsm.isNearWin, "isNearWin should have been set to true.");
     gsm.toggleNearWin();
     Assert.IsTrue(!gsm.isNearWin, "isNearWin should be false again.");
 }
Example #3
0
 public void loadExistingData(GameSetupModel savedSetup)
 {
     TotalPicksSlider.Value = savedSetup.totalPicks;
     gsObject.totalPicks = savedSetup.totalPicks;
     NearWinCheckbox.IsChecked = savedSetup.isNearWin;
     NumNearWinsSlider.Value = savedSetup.nearWins;
     gsObject = savedSetup;
     gsObject.initializeListener();
     Window parentWindow = Window.GetWindow(this.Parent);
     gsObject.addListener((Window1)parentWindow);
     pickCheck = gsObject.totalPicks;
 }
Example #4
0
 public GameSetupUC()
 {
     InitializeComponent();
     TotalPicksSlider.Value = 2;
     gsObject = new GameSetupModel();
     gsObject.canCreate = true;
     CreateButton.DataContext = gsObject;
     gsObject.totalPicks = 2;
     pickCheck = gsObject.totalPicks;
     ErrorTextBlock.DataContext = ErrorService.Instance;
     WarningTextBlock.DataContext = ErrorService.Instance;
     errorPanelScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
 }
Example #5
0
        public void loadExistingData(GameSetupModel savedSetup)
        {
            TotalPicksSlider.Value      = savedSetup.totalPicks;
            gsObject.totalPicks         = savedSetup.totalPicks;
            NearWinCheckbox.IsChecked   = savedSetup.isNearWin;
            NumNearWinsSlider.Value     = savedSetup.nearWins;
            MaxPermutationsTextBox.Text = savedSetup.maxPermutations.ToString();
            gsObject = savedSetup;
            gsObject.initializeListener();
            Window parentWindow = Window.GetWindow(this.Parent);

            gsObject.addListener((Window1)parentWindow);
            pickCheck = gsObject.totalPicks;
        }
Example #6
0
 public GameSetupUC()
 {
     InitializeComponent();
     TotalPicksSlider.Value = 2;
     gsObject                     = new GameSetupModel();
     gsObject.canCreate           = true;
     CreateButton.DataContext     = gsObject;
     gsObject.totalPicks          = 2;
     pickCheck                    = gsObject.totalPicks;
     ErrorTextBlock.DataContext   = ErrorService.Instance;
     WarningTextBlock.DataContext = ErrorService.Instance;
     errorPanelScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
     //gameSetupScroll.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
 }
Example #7
0
        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);
            }
        }
Example #8
0
        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 TestNearWinsGetSet()
 {
     GameSetupModel gsm = new GameSetupModel();
     gsm.NearWins = 5;
     Assert.IsTrue(gsm.NearWins == 5, "NearWins should have been set to 5.");
 }
 public void TestMaxPermutationsGetSet()
 {
     GameSetupModel gsm = new GameSetupModel();
     gsm.MaxPermutations = 5;
     Assert.IsTrue(gsm.MaxPermutations == 5, "MaxPermutations should have been set to 5.");
 }
        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");
        }
Example #14
0
 public void TestTotalPicksGetSet()
 {
     GameSetupModel gsm = new GameSetupModel();
     gsm.totalPicks = 5;
     Assert.IsTrue(gsm.totalPicks == 5, "totalPicks should have been set to 5.");
 }
Example #15
0
 public void TestIsNearWinGetSet()
 {
     GameSetupModel gsm = new GameSetupModel();
     gsm.isNearWin = true;
     Assert.IsTrue(gsm.isNearWin, "isNearWin should have been set to true.");
 }