diff options
author | dmazzone <mazzone.diego@gmail.com> | 2010-12-13 17:08:49 (GMT) |
---|---|---|
committer | dmazzone <mazzone.diego@gmail.com> | 2010-12-13 17:08:49 (GMT) |
commit | f60352be94bbee1cd57814371e17c01f60f8efad (patch) | |
tree | 66b86335bb42ca1fcedd6b9235f3c17e909c2da6 | |
parent | 389519ca3dc2fc2f8734701bea88fcf117431fc4 (diff) |
Improvements on challenges module.
New type of challenge: True or False
-rwxr-xr-x | Saludame.activity/challenges.py | 21 | ||||
-rwxr-xr-x | Saludame.activity/challenges_creator.py | 48 | ||||
-rwxr-xr-x | Saludame.activity/game_manager.py | 2 | ||||
-rwxr-xr-x | Saludame.activity/main_window.py | 18 |
4 files changed, 67 insertions, 22 deletions
diff --git a/Saludame.activity/challenges.py b/Saludame.activity/challenges.py index 4bb9f5c..cf7caa4 100755 --- a/Saludame.activity/challenges.py +++ b/Saludame.activity/challenges.py @@ -13,6 +13,8 @@ S_CORRECT_PATH = os.path.normpath("assets/sound/correct.ogg") S_OVER_PATH = os.path.normpath("assets/sound/over.ogg") S_INCORRECT_PATH = os.path.normpath("assets/sound/incorrect.ogg") +N_TF = 4 + FIN_MC = False # Toma el valor True cuando finaliza el juego de multiple choice TITLE_FONT_SIZE = 24 @@ -23,7 +25,7 @@ MOUSE_OVER_COLOR = pygame.Color("green") class MultipleChoice(Window): - def __init__(self, container, rect, frame_rate, windows_controller, bg_color=(0, 0, 0)): + def __init__(self, container, rect, frame_rate, windows_controller, challenges_creator, bg_color=(0, 0, 0)): Window.__init__(self, container, rect, frame_rate, windows_controller, "challenges_window", bg_color) ###### Sounds ###### @@ -35,6 +37,11 @@ class MultipleChoice(Window): self.choices = [] self.correct = 0 + self.kind = "mc" + self.n_tf = N_TF + + self.challenges_creator = challenges_creator + # If a question is setted, we have to "erase" the old challenge self.question = None @@ -70,7 +77,7 @@ class MultipleChoice(Window): Problema: "corta" la pregunta en un valor hardcodeado el cual muchas veces "corta" a una palabra en cualquier lado. """ - if (self.question.rect_in_container.width > self.rect.width -20): + if (self.question.rect_in_container.width > self.rect.width - 20): q1 = Text(self.rect, 30, 30, 1, question[:43], TITLE_FONT_SIZE, (0, 255, 0)) q2 = Text(self.rect, 30, 65, 1, question[43:], TITLE_FONT_SIZE, (0, 255, 0)) self.add_child(q1) @@ -130,7 +137,15 @@ class MultipleChoice(Window): if(button == self.choices[self.correct]): self.s_correct.play() self.windows_controller.game_man.add_points(self.win_points) - FIN_MC = True # Damos por finalizada la pregunta + if self.kind == "tf": + if self.n_tf: + self.n_tf -= 1 + self.challenges_creator.get_challenge("tf") + else: + FIN_MC = True # Damos por finalizado el desafío + self.n_tf = N_TF + else: + FIN_MC = True # Damos por finalizado el desafío else: self.windows_controller.game_man.add_points(-self.lose_points) self.s_incorrect.play() diff --git a/Saludame.activity/challenges_creator.py b/Saludame.activity/challenges_creator.py index b8c2400..bfdc2e8 100755 --- a/Saludame.activity/challenges_creator.py +++ b/Saludame.activity/challenges_creator.py @@ -17,32 +17,54 @@ class ChallengesCreator: self.bg_color = bg_color # Multiple Choice window - self.challenge = challenges.MultipleChoice(self.container, self.rect, self.frame_rate, self.windows_controller, self.bg_color) + self.challenge = challenges.MultipleChoice(self.container, self.rect, self.frame_rate, self.windows_controller, self, self.bg_color) self.challenge.set_bg_image("assets/windows/window_1.png") - # Tuples of challenges - self.challenges = [] + # Tuples of mc_challenges + self.mc_challenges = [] + + # Tuples of tf_challenges + self.tf_challenges = [] def create_challenges(self): - self._create_challenge(_("Which foods do we need to eat every day?"), [_("Some food from each group every day"), _("Some fruits and vegetables only"), _("Some food from all the groups but not fats and sugar")], 0, 10, 10) - self._create_challenge(_("What is the most important meal of the day?"), [_("Breakfast"), _("Lunch"), _("Tea"), _("Dinner")], 0, 10, 10) - self._create_challenge(_("How regularly should children exercise?"), [_("Once a month"), _("Once a week"), _("Once a day")], 2, 10, 10) - self._create_challenge(_("What percentage of the body is made up of water?"), ["30%", "70%", "90%"], 1, 10, 10) + # Common multiple choice + self._create_mc_challenge(_("Which foods do we need to eat every day?"), [_("Some food from each group every day"), _("Some fruits and vegetables only"), _("Some food from all the groups but not fats and sugar")], 0, 10, 10) + self._create_mc_challenge(_("What is the most important meal of the day?"), [_("Breakfast"), _("Lunch"), _("Tea"), _("Dinner")], 0, 10, 10) + self._create_mc_challenge(_("How regularly should children exercise?"), [_("Once a month"), _("Once a week"), _("Once a day")], 2, 10, 10) + self._create_mc_challenge(_("What percentage of the body is made up of water?"), ["30%", "70%", "90%"], 1, 10, 10) + + # True or false + # 0 = False | 1 = True + self._create_tf_challenge(_("The 70% of the body is made up of water"), 1, 10, 10) + self._create_tf_challenge(_("Breakfast is the most important meal of the day"), 1, 10, 10) + self._create_tf_challenge(_("Children should exercise once a month"), 0, 10, 10) - def _create_challenge(self, question, answers, correct_answer, win_points, lose_points, image=None): + def _create_mc_challenge(self, question, answers, correct_answer, win_points, lose_points, image=None): """ Create a new challenge (tuple) """ challenge = (question, answers, correct_answer, win_points, lose_points, image) - self.challenges.append(challenge) + self.mc_challenges.append(challenge) + + def _create_tf_challenge(self, question, correct_answer, win_points, lose_points, image=None): + """ + Create a new tf_challenge (tuple) + """ + challenge = (question, ["False", "True"], correct_answer, win_points, lose_points, image) + self.tf_challenges.append(challenge) - def get_challenge(self): + def get_challenge(self, kind): """ Load and return a random "created" challenge """ - r = random.randrange(0, len(self.challenges)) - # Obtain a challenge tuple - c = self.challenges[r] + if kind == "mc": + self.challenge.kind = "mc" + r = random.randrange(0, len(self.mc_challenges)) + c = self.mc_challenges[r] + elif kind == "tf": + self.challenge.kind = "tf" + r = random.randrange(0, len(self.tf_challenges)) + c = self.tf_challenges[r] # Set multiple choice attributes self.challenge.set_question(c[0]) diff --git a/Saludame.activity/game_manager.py b/Saludame.activity/game_manager.py index 6c8104a..c58512a 100755 --- a/Saludame.activity/game_manager.py +++ b/Saludame.activity/game_manager.py @@ -454,7 +454,7 @@ class GameManager: # If it is answered correctly the player wins some points, so he starts the new level with these points # Otherwise it loses some points, and continues in the same level, so he has to continue playing to # reach the master challenge again. - self.challenges_creator.get_challenge() + self.challenges_creator.get_challenge("mc") self.windows_controller.set_active_window("challenges_window") # Save and load game diff --git a/Saludame.activity/main_window.py b/Saludame.activity/main_window.py index 87fa876..46c3901 100755 --- a/Saludame.activity/main_window.py +++ b/Saludame.activity/main_window.py @@ -34,9 +34,13 @@ class MainWindow(Window): self.add_child(Clock(container, pygame.Rect(0, 528, 1, 1), 1, game_man)) # Challenges - #challenges_button = ImageButton(self.rect, pygame.Rect((1120, 400), (60, 60)), 1, "challenges/trophy.png", self._cb_button_click_challenges) - #challenges_button.set_tooltip(_("Challenges module")) - #self.add_button(challenges_button) + challenges_button = ImageButton(self.rect, pygame.Rect((1120, 400), (60, 60)), 1, "challenges/trophy.png", self._cb_button_click_mc_challenges) + challenges_button.set_tooltip(_("Multiple choice")) + self.add_button(challenges_button) + + challenges_button2 = ImageButton(self.rect, pygame.Rect((1120, 500), (60, 60)), 1, "challenges/trophy.png", self._cb_button_click_tf_challenges) + challenges_button2.set_tooltip(_("True or false")) + self.add_button(challenges_button2) #stop_animation_button = TextButton(self.rect, pygame.Rect((800, 550), (30, 30)), 1, "Stop animation", 38, (255, 0, 0), self._cb_button_click_stop_animation) #self.add_button(stop_animation_button) @@ -45,8 +49,12 @@ class MainWindow(Window): #self.add_button(btn_change_mood) #### Callbacks #### - def _cb_button_click_challenges(self, button): - self.cha_loader.get_challenge() + def _cb_button_click_mc_challenges(self, button): + self.cha_loader.get_challenge("mc") + self.windows_controller.set_active_window("challenges_window") + + def _cb_button_click_tf_challenges(self, button): + self.cha_loader.get_challenge("tf") self.windows_controller.set_active_window("challenges_window") def _cb_button_click_stop_animation(self, button): |