@Test
  public void testPersistence() {
    try {

      em.getTransaction().begin();

      Student u = new Student();
      u.setScore(12);
      u.setName("eskatos");

      em.persist(u);
      assertTrue(em.contains(u));

      em.remove(u);

      assertFalse(em.contains(u));

      em.getTransaction().commit();

    } catch (Exception ex) {
      em.getTransaction().rollback();
      ex.printStackTrace();
      fail("Exception during testPersistence");
    }
  }
Ejemplo n.º 2
0
 /** Method run in case of wrong answer. */
 private void answeredWrongly() {
   student.increaseNumberOfWrongAnswers();
   if (student.getNumberOfWrongAnswers() >= 9) {
     student.setNumberOfWrongAnswers(0);
     changeDifficulty(student.getDifficulty() - 1);
   }
 }
Ejemplo n.º 3
0
 /** Method run in case of correct answer. */
 private void answeredCorrectly() {
   increaseScore();
   student.increaseNumberOfCorrectAnswers();
   if (student.getNumberOfRightAnswers() >= 9) {
     changeDifficulty(student.getDifficulty() + 1);
     student.setNumberOfRightAnswers(0);
   }
 }
Ejemplo n.º 4
0
 /**
  * Sets the desired difficulty.
  *
  * @param difficulty Integer; 1-10
  */
 public void changeDifficulty(int difficulty) {
   student.setDifficulty(difficulty);
   this.questionsController =
       new QuestionsController(10, student.getDifficulty(), student.getOperationType());
 }
Ejemplo n.º 5
0
 /**
  * Sets a new score for the student.
  *
  * @param newScore Integer. The new score to set.
  */
 public void setScore(int newScore) {
   student.setScore(newScore);
 }
Ejemplo n.º 6
0
 /** @return Returns the students score. */
 public int getScore() {
   return student.getScore();
 }
Ejemplo n.º 7
0
 /** @return The players username. */
 public String getPlayerName() {
   return student.getName();
 }
Ejemplo n.º 8
0
 /** When called; increases the students score by the amount set in REWARD_SCORE (10) */
 protected void increaseScore() {
   student.setScore(student.getScore() + REWARD_SCORE);
 }
Ejemplo n.º 9
0
 /** @param student An Object of the class Student. */
 public GameController(Student student) {
   this.student = student;
   this.questionsController =
       new QuestionsController(10, student.getDifficulty(), student.getOperationType());
 }
Ejemplo n.º 10
0
 /**
  * ADDITION = 0; SUBTRACTION = 1; MULTIPLICATION = 2; DIVISION = 3;
  *
  * @param playerName The students username
  * @param operationType Desired operation type; addition, substraction, multiplication, division.
  * @param difficulty Desired difficulty at game start. Will dynamically change to accomodate the
  *     students skill-level.
  */
 public GameController(String playerName, int operationType, int difficulty) {
   student = new Student(playerName);
   student.setOperationType(operationType);
   this.questionsController = new QuestionsController(10, difficulty, operationType);
   restoreGame();
 }