// moves the shifts the workout to the next exercise public void NextExercise() { // remove component from game components _game.Components.Remove(CurrentExercise); // complete the exercise CompletedExercises.Enqueue(CurrentExercise); if (null != CurrentExercise) { foreach (StartedRepetitionEventHandler evt in RepetitionStartedListener) { CurrentExercise.Changed -= evt; } } // grab the next (or first) one and add to game components CurrentExercise = PendingExercises.Dequeue(); // be sure to add any listeners foreach (StartedRepetitionEventHandler evt in RepetitionStartedListener) { CurrentExercise.Changed += evt; } _game.Components.Add(CurrentExercise); }
/// <summary> /// When the catalog notifies that the Exercises have been loaded and the patient is ready to exercise, /// The exercise queue will load up the exercises pushed into the CurrentCatalog. /// /// </summary> /// <returns></returns> public void LoadExercises(object sender, CatalogCompleteEventArg e) { ReInitialize(); OnLoadStarted(EventArgs.Empty); string path = System.AppDomain.CurrentDomain.BaseDirectory + "../../../../KinectTherapyContent/Exercises/"; Exercises = new ExerciseGameComponent[e.Exercises.Length]; //loop through the exercises in the CurrentCatalog and turn them into Exercise objects. for (int i = 0; i < e.Exercises.Length; i++) { XmlSerializer serializer = new XmlSerializer(typeof(Exercise)); StreamReader reader = new StreamReader(path + e.Exercises[i].Id + ".xml"); // deserialize the xml and create an Exercise Exercise temp = (Exercise)serializer.Deserialize(reader); temp.Repetitions = e.Exercises[i].Repetitions; temp.Variance = e.Exercises[i].Variance; Exercises[i] = new ExerciseGameComponent(_game, temp); reader.Close(); //Queue up for a workout PendingExercises.Enqueue(Exercises[i]); } // once they're all queued start the first exercise. NextExercise(); OnLoadComplete(EventArgs.Empty); }