// Test that all minigames by subject and filter are pulled from the database public void GetMiniGamesBySubjectAndFilter() { int difficulty = 2; int catID = 1; List <MiniGame> minigames = _minigame.GetListPlayable(catID, difficulty); List <string> result = new List <string>(); for (int i = 0; i < minigames.Count; i++) { result.Add(minigames[i].MiniGameName); } List <string> expected = new List <string>(); expected.Add("AlphabetBubblePop"); expected.Add("AlphabetTracing"); expected.Add("ColorSortingGame"); expected.Add("AlphabetMatching"); expected.Add("AlphabetMatching"); expected.Add("Typing"); expected.Add("AlphabetMatching"); expected.Add("ISpy"); CollectionAssert.AreEqual(expected, result); }
//page that executes minigame script, set MiniGame model public ActionResult MiniGame() { MiniGameModel model = new MiniGameModel(); Random random = new Random(); List <MiniGame> minigames = new List <MiniGame>(); if (User.Identity.IsAuthenticated) { Options profileSettings = _options.Get((int)Session["profileID"]); int catID = 0; //category id //get subject filter for profile, if no filter, randomly choose a subject for minigame if (profileSettings.SubjectFilter == "Reading") { catID = 1; } else if (profileSettings.SubjectFilter == "Math") { catID = 2; } else { catID = random.Next(1, 3); //no subject filter, randomly choose a minigame category } //get a list of minigames that adheres to subject filter and difficulty level if (catID == 1) { minigames = _minigame.GetListPlayable(catID, profileSettings.ReadingDifficultyLevel); //catID, difficulty level model.Difficulty = profileSettings.ReadingDifficultyLevel; //difficult level for model } else if (catID == 2) { minigames = _minigame.GetListPlayable(catID, profileSettings.MathDifficultyLevel); //catID, difficulty level model.Difficulty = profileSettings.MathDifficultyLevel; //difficulty level for model } //get list or recently played minigames List <int> playedgames = _minigame.GetListRecentlyPlayed((int)Session["profileID"]); //randomly choose a minigame that isn't in list of recently played, assign a minigame to the model int ranGame = random.Next(0, minigames.Count()); //generate an index between 1 and num of playable games //continue generating random gameID while recently played game is randomly selected bool played = true; int loopCounter = 0; while (played == true) { played = false; for (int i = 0; i < playedgames.Count(); i++) { if (minigames[ranGame].ID == playedgames[i]) { //generate an index between 0 and num of playable games ranGame = random.Next(0, minigames.Count()); played = true; } } loopCounter++; //increment number of times through loop if (loopCounter >= 50) //Ensure that game doesn't get stuck in endless loop if not enough minigames { played = false; } //choose a different minigame if device is mobile and chosen game isn't mobile friendly //letter sound racing, typing, tangram if (DetectMobile() && (minigames[ranGame].ID == 18 || minigames[ranGame].ID == 19 || minigames[ranGame].ID == 4)) { played = true; } //if the browser isn't chrome and tangram is played if (!IsBrowserChrome() && minigames[ranGame].ID == 19) { played = true; } } model.MiniGameID = minigames[ranGame].ID; model.CategoryID = minigames[ranGame].MiniGameCategoryID; model.MiniGame = minigames[ranGame].MiniGamePath; } else //free play mode { minigames = _minigame.GetAllMinigames(); //get a list of all minigames from database int ranGame = random.Next(0, minigames.Count()); //generate an index between 0 and num of games //choose a different minigame if device is mobile and chosen game isn't mobile friendly //letter sound racing, typing, tangram while ((DetectMobile() && (minigames[ranGame].ID == 18 || minigames[ranGame].ID == 19 || minigames[ranGame].ID == 4)) || (!IsBrowserChrome() && minigames[ranGame].ID == 19)) { ranGame = random.Next(0, minigames.Count()); //generate an index between 0 and num of games } model.MiniGameID = minigames[ranGame].ID; model.MiniGame = minigames[ranGame].MiniGamePath; model.CategoryID = minigames[ranGame].MiniGameCategoryID; model.CategoryID = minigames[ranGame].MiniGameCategoryID; model.Difficulty = 0; //difficulty doesn't apply to free play mode } model.ToggleSound = Convert.ToString((bool)Session["toggleSound"]); //set model's toggle value for sound model.ToggleMusic = Convert.ToString((bool)Session["toggleMusic"]); //set model's toggle value for music return(View(model)); }