Skip to content

How to add an exercise

marionlb edited this page Feb 8, 2012 · 14 revisions

An exercise is part of a lesson. In this case, we're assuming the lesson already exists and we only want to add an exercise (a tab) to it.
If you want to create a whole new lesson, see How to create a lesson

  1. Find the package you want to add to. It will be something like lesson.nameOfTheLesson. For the sake of explaining, let's take lesson.maze.

  2. Check out the Main class from the package you chose.

  • You'll find it extends the abstract class Lesson. (more on that in How to create a lesson)
  • Notice how to add an exercise :
protected void loadExercises() {  
    addExercise(new MyFirstExercise(this));  
    addExercise(new MySecondExercise(this)); 
    addExercise(new MyThirdExercise(this));  
}
  1. Now you need to create your Exercise class. It needs to extend ExerciseTemplated

    • The constructor takes a Lesson as a parameter, just start with super(lesson).
    • Create a world (any class extending World)
    • Call setup(myWorld)
  2. Create a class extending the entity of the world you've chosen.
    The Entity class contains a run() method which contains the solution code and the student-written code.

/* BEGIN TEMPLATE */
    // Any hint for the users
    MethodToWrite()  {
/* BEGIN SOLUTION */
    Le code de la solution
/* END SOLUTION */
/* END TEMPLATE * 
  1. Add the new exercise in the Main class the same way as in 2.
    addExercice(new MyExercice(this))

  2. Add a HTML description file MyExercice.html

Clone this wiki locally