/// <summary> /// Sets the UI for the game screen. /// </summary> private void setUI(StudentProblem curProb) { AddSubProblem prob = curProb.Problem; Session["CurAnswer"] = prob.Result; string ord1 = prob.Operator1.ToString(); string ord2 = prob.Operator2.ToString(); // set the images for the UI imgOpSign.ImageUrl = "images/signs/plus.png"; imgOrd1.ImageUrl = "images/nums/" + ord1 + ".png"; imgOrd2.ImageUrl = "images/nums/" + ord2 + ".png"; // set alternate text imgOpSign.AlternateText = "+"; imgOrd1.AlternateText = ord1; imgOrd2.AlternateText = ord2; }
// Randomly fill problem list with problems from the appropriate level and problem type // TODO Currently hard coded for the first 55 problems, which are Addition Level 1 // TODO Create a SQL query which gets a list of all IDs for the appropriate ProblemType and Level // TODO Then generate random IDs based on that list private void PopulateProblemList() { //int id; AddSubProblem thisAddSubProb; Result thisResult; // Open a connection to the DB using (DataClassesDataContext dc = new DataClassesDataContext()) { // Random number generator for problem IDs Random r = new Random(); // Fill the ProblemList with problems, based on // the problem ID, which is randomly generated for (int i = 0; i < NUM_PROBS_PER_ROUND; i++) { // Random ID // TODO random seed currently hardcoded to 0..55 int id = r.Next(LOWEST_PROBLEM_ID, (HIGHEST_PROBLEM_ID + 1)); // Set the sql string var temp = dc.AddSubProblems.Where(x => x.AddSubProblemID == id).First(); thisAddSubProb = (AddSubProblem)(dc.AddSubProblems.Where(x => x.AddSubProblemID == id)).First(); // Create the new Result thisResult = new Result(); // Pre-set values in the new Result thisResult.ProblemID = id; thisResult.Level = thisAddSubProb.Level; // Create a new StudentProblem StudentProblem sp = new StudentProblem(thisAddSubProb, thisResult); // Add to problem list ProblemList.Add(sp); } } }
// Randomly fill problem list with problems from the appropriate level and problem type // TODO: Query the Results table for id = StudentID, level = Level, and problem type = ProbType // This should return a list of the missed problems of this type in this level. // Use these values to start the PopulateProblemList list private void PopulateProblemList() { AddSubProblem thisAddSubProb = null; Result thisResult; // Open a connection to the DB using (DataClassesDataContext dc = new DataClassesDataContext()) { // RELEASE 2: // Remove the 0..55 range, and replace // it with a random selection where Level = desired level // NEWID() provides a randomization function. // See MSDN, Selecting Rows Randomly from a Large Table // https://msdn.microsoft.com/en-us/library/cc441928.aspx // Get list of *missed* problem IDs for this level // This will form the first part of the problem list var missedProbs = dc.GetMissedProblems(sid, (int)probType); List <int> missedProbIds = new List <int>(); foreach (GetMissedProblemsResult m in missedProbs) { missedProbIds.Add(m.ProblemID); } // Now get a list of *new* problem IDs for this level and problem type var problemQuery = dc.GetProblemIDs((int)probType, level); List <int> newProbIds = new List <int>(); foreach (GetProblemIDsResult i in problemQuery) { newProbIds.Add(i.AddSubProblemID); } // Finally, combine the lists. // For now, we will start with missed problem ids, // and fill the rest of the list with new problem ids // There will be problem ids that are not covered in this round // TODO: How to deal with more than NUM_PROBS_PER_ROUND missed problems? List <int> allProbIds = new List <int>(); // At most, the number of missed problems to be shown // is the number of problems in the current round int numMissedShown = Math.Min(missedProbIds.Count, NUM_PROBS_PER_ROUND); // If there are any problems not yet used, the slots will // be filled by new problems int numNewShown = NUM_PROBS_PER_ROUND - numMissedShown; for (int i = 0; i < numMissedShown; i++) { allProbIds.Add(missedProbIds[i]); } int newProbCount = 0; for (int i = numMissedShown; i < NUM_PROBS_PER_ROUND; i++) { allProbIds.Add(newProbIds[newProbCount++]); } // Get problems based on the list of ids var problems = dc.GetProblems(allProbIds); foreach (var prob in problems) { // Create the new Result thisResult = new Result(); // Pre-set values in the new Result thisResult.ProblemID = prob.AddSubProblemID; thisResult.Level = prob.Level; // Create a new StudentProblem StudentProblem sp = new StudentProblem(prob, thisResult); // new StudentProblem(thisAddSubProb, thisResult); // Add to problem list ProblemList.Add(sp); } } }
/// <summary> /// Submits student's answer and checks against stored answer. /// Displays pop up with Correct/Incorrect and sets the UI for the next problem. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, ImageClickEventArgs e) { // check that the user input is not blank if (String.IsNullOrWhiteSpace(txtStudentInput.Text)) { return; // return out if the input is blank } // get index value from hidden label int idx; Int32.TryParse(lblProbIdx.Text, out idx); // get student answer from textbox int studentAnswer; Int32.TryParse(txtStudentInput.Text, out studentAnswer); txtStudentInput.Text = ""; ProblemSet probSet = (ProblemSet)Session["CurProbSet"]; StudentProblem curProb = probSet.ProblemList[idx]; // correct answer if (studentAnswer == curProb.Problem.Result) { // add happy cookie image imgCookie.ImageUrl = "images/cookie-happy.png"; imgCookie.AlternateText = "Happy Cookie"; //change the label text and color lblAnswerResult.Text = "Correct!"; //lblAnswerResult.ForeColor = "#9BFF3A"; // increment right answers int x = (int)Session["RightAnswerCount"]; Session["RightAnswerCount"] = ++x; } // incorrect answer else { // add sad cookie image imgCookie.ImageUrl = "images/cookie-sad.png"; imgCookie.AlternateText = "Sad Cookie"; //change the label text and color lblAnswerResult.Text = "Incorrect!"; // lblAnswerResult.ForeColor = "#E52B14"; // increment wrong answers int x = (int)Session["WrongAnswerCount"]; Session["WrongAnswerCount"] = ++x; } // Store problem and student's answer as a Result object Result result = new Result(); result.StudentID = (int)Session["UserID"]; result.ProblemID = curProb.Problem.AddSubProblemID; result.Answer = studentAnswer; result.Level = curProb.Problem.Level; result.Round = (int)Session["CurRound"]; // Add the result to the list node curProb.studentResult = result; // bring up the results pop up panel pnlGame.Visible = false; pnlResults.Visible = true; // check if we've reached the end of the list if (++idx >= probSet.ProblemList.Count) { // save the results to the DB probSet.SaveResults(); lblGameOver.Text = "true"; // advance the round int round = (int)Session["CurRound"]; Session["CurRound"] = ++round; // switch panels to display setFinal(); } else { // store current index in hidden label lblProbIdx.Text = idx.ToString(); // move to the next problem setUI(probSet.ProblemList[idx]); } }