Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Major <jmikem@bellsouth.net>2009-06-03 01:27:34 (GMT)
committer Mike Major <jmikem@bellsouth.net>2009-06-03 01:27:34 (GMT)
commit1f2a32a03a7f2d2f79476050978b4ebaf83ffc51 (patch)
tree244fab29ecfcba725758d0dc208f2667f3b719bb
parent54cb05cf88f35b8bddd81df1bcf5e56b4178dfd2 (diff)
multiple choice now works. the player may enter the answer
directly or click a mult choice button. revision 5
-rw-r--r--activity/activity.info2
-rwxr-xr-x[-rw-r--r--]hoparound.py133
2 files changed, 101 insertions, 34 deletions
diff --git a/activity/activity.info b/activity/activity.info
index 1dcd148..0222a72 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -3,6 +3,6 @@ name = Hop-A-Round
bundle_id = org.laptop.HopaRound
class = hoparound.HopaRoundActivity
icon = hoparound-icon
-activity_version = 4
+activity_version = 5
host_version = 1
show_launcher = yes
diff --git a/hoparound.py b/hoparound.py
index 199dac0..7d557be 100644..100755
--- a/hoparound.py
+++ b/hoparound.py
@@ -5,7 +5,7 @@ from sugar.activity import activity
class HopaRoundActivity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
- print "INFO: activity running", handle
+ print "INFO: activity running"
# make the toolbox
toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
@@ -13,88 +13,155 @@ class HopaRoundActivity(activity.Activity):
#initialize variables
print "INFO: initialize variables"
self.decades = (10,100,1000,10000,100000)
- self.rounded={0:0,10:0,100:0,1000:0,10000:0,100000:0}
+ self.rounded={0:0,1:1,2:2,3:3,4:4,9:0,10:0,11:0,99:0,100:0,101:0,999:0,1000:0,1001:0,9999:0,10000:0,10001:0,99999:0,100000:0,100001:0}
self.lower_bound = 1
self.upper_bound = 500000
+ self.correct = 0
+ self.incorrect = 0
+ self.dec_answer = 0
random.seed()
#create view ports
print "INFO: create view ports"
- self.main_view = gtk.HBox()
+ self.main_view = gtk.VBox()
+ self.panes = gtk.HBox(True)
self.left_view = gtk.VBox()
+ self.mid_view = gtk.VBox()
self.right_view = gtk.VBox()
- self.main_view.pack_start(self.left_view, False, False, 10)
- self.main_view.pack_start(self.right_view, False, False, 10)
self.instructions = gtk.Label()
self.instructions.set_justify(gtk.JUSTIFY_LEFT)
- self.instructions.set_markup("\n\n\nLet's play...")
+ self.instructions.set_markup("\n\nLet's play...")
+ self.type_answer_instructions = gtk.Label("Type your answer below")
+ self.mult_instructions = gtk.Label("Choose one of the answers below")
self.answer = gtk.Entry()
self.answer.set_text("?")
+ self.answer.connect("activate", self.check_answer, 0)
self.play_btn = gtk.Button("Play")
- self.play_btn.connect("clicked", self.play, None)
+ self.play_btn.connect("clicked", self.play)
self.check_answer_btn = gtk.Button("Check Answer")
- self.check_answer_btn.connect("clicked", self.check_answer, None)
+ self.check_answer_btn.connect("clicked", self.check_answer, 0)
+ self.mult_1 = gtk.Button()
+ self.mult_1.connect("clicked", self.check_answer, 1)
+ self.mult_2 = gtk.Button()
+ self.mult_2.connect("clicked", self.check_answer, 2)
+ self.mult_3 = gtk.Button()
+ self.mult_3.connect("clicked", self.check_answer, 3)
+ self.mult_4 = gtk.Button()
+ self.mult_4.connect("clicked", self.check_answer, 4)
self.output = gtk.Label()
self.output.set_justify(gtk.JUSTIFY_LEFT)
#show the widgets
print "INFO: show widgets"
- self.left_view.pack_start(self.instructions, False, False, 10)
+ self.main_view.pack_start(self.instructions, False, False, 10)
+ self.main_view.pack_start(self.play_btn, False, False, 10)
+ self.main_view.pack_start(self.panes, False, False, 10)
+ self.panes.pack_start(self.left_view, False, False, 10)
+ self.panes.pack_start(self.mid_view, False, False, 10)
+ self.panes.pack_start(self.right_view, False, False, 10)
+ self.left_view.pack_start(self.type_answer_instructions, False, False, 10)
self.left_view.pack_start(self.answer, False, False, 10)
- self.left_view.pack_start(self.play_btn, False, False, 10)
self.left_view.pack_start(self.check_answer_btn, False, False, 10)
+ self.mid_view.pack_start(self.mult_instructions, False, False, 10)
+ self.mid_view.pack_start(self.mult_1, False, False, 10)
+ self.mid_view.pack_start(self.mult_2, False, False, 10)
+ self.mid_view.pack_start(self.mult_3, False, False, 10)
+ self.mid_view.pack_start(self.mult_4, False, False, 10)
self.right_view.pack_start(self.output, False, False, 10)
self.set_canvas(self.main_view)
self.show_all()
+ self.play_btn.grab_focus()
- def play(self, widget, data=None):
+ def play(self, widget):
print "INFO: play clicked"
+ self.dec_answer = random.choice(self.decades)
self.gen_random(self)
- self.dec_answer = random.choice(decades)
- self.guesses = 0
self.answer.set_text("?")
- message = "Round the number <b>"
+ message = "Correct:\t\t" + str(self.correct)
+ message += "\nIncorrect:\t" + str(self.incorrect)
+ self.output.set_markup(message)
+ message = "\nRound the number <b>"
message += str(self.rounded[0])
- message += "\n</b>to the nearest <b>"
+ message += "</b> to the nearest <b>"
message += str(self.dec_answer)
- message += "</b>:"
- message += "\n\nEnter your answer below"
+ message += "</b>:\n"
self.instructions.set_markup(message)
- self.output.set_markup("")
+ self.mult_1.set_label(str(self.rounded[1]))
+ self.mult_2.set_label(str(self.rounded[2]))
+ self.mult_3.set_label(str(self.rounded[3]))
+ self.mult_4.set_label(str(self.rounded[4]))
#self.show_random_numbers(self)
self.answer.grab_focus()
- def check_answer(self, widget, data=None):
+ def check_answer(self, widget, response=None):
print "INFO: check answer clicked"
+ print "INFO: response = '" + str(response) + "'"
try:
- if int(self.answer.get_text()) == self.rounded[self.dec_answer]:
- message = "\t<b>That's correct!</b>"
+ if response == 0:
+ print "INFO: entry = '" + str(self.answer.get_text()) + "'"
+ response = int(self.answer.get_text())
+ elif response == 1: response = self.rounded[response]
+ elif response == 2: response = self.rounded[response]
+ elif response == 3: response = self.rounded[response]
+ elif response == 4: response = self.rounded[response]
+ if response == self.rounded[self.dec_answer]:
+ self.correct += 1
+ message = "Correct:\t\t" + str(self.correct)
+ message += "\nIncorrect:\t" + str(self.incorrect)
+ message += "\n\n<b>That's correct!</b>"
self.output.set_markup(message)
- self.guesses = 0
- self.instructions.set_markup("\n\n\nLet's play...")
+ self.instructions.set_markup("\n\nLet's play...")
self.answer.set_text("?")
self.play_btn.grab_focus()
else:
- self.guesses += 1
- message = "<span foreground=\"red\">\n\t<b>Sorry, guess " + str(self.guesses) + " wrong...</b></span>"
+ self.incorrect += 1
+ message = "Correct:\t\t" + str(self.correct)
+ message += "\nIncorrect:\t" + str(self.incorrect)
+ message += "<span foreground=\"red\">\n\n<b>Sorry, the correct answer was\n" + str(self.rounded[self.dec_answer])
+ message += "\n\nYou answered\n" + str(response)
+ message += "</b></span>"
self.output.set_markup(message)
- self.answer.grab_focus()
+ self.answer.set_text("?")
+ self.play_btn.grab_focus()
except:
- self.guesses += 1
- message = "<span foreground=\"red\">Please enter a number guess only.\n\t<b>Sorry, guess " + str(self.guesses) + " wrong...</b></span>"
+ message = "<span foreground=\"red\"><b>Please enter a number only.</b></span>"
self.output.set_markup(message)
self.answer.grab_focus()
- def gen_random(self, widget, data=None):
+ def gen_random(self, widget):
print "INFO: generating random number"
+ #generate a random number and round it to the different decades
self.rounded[0] = random.randint(self.lower_bound,self.upper_bound)
for item in self.decades:
+ self.rounded[item-1] = int(math.floor(self.rounded[0]/(item*1.0)) * item)
self.rounded[item] = int(round(self.rounded[0]/(item*1.0), 0) * item)
+ self.rounded[item+1] = int(math.ceil(self.rounded[0]/(item*1.0)) * item)
+ #create a list of decades that are not the right answer and choose one
+ self.dec_temp_list = [10, 100, 1000, 10000, 100000]
+ del self.dec_temp_list[self.dec_temp_list.index(self.dec_answer)]
+ self.dec_temp = random.choice(self.dec_temp_list)
+ #generate the multiple choice answer set
+ self.mult = range(1,5)
+ self.mult_temp = random.choice(self.mult)
+ self.rounded[self.mult_temp] = self.rounded[self.dec_answer - 1]
+ del self.mult[self.mult.index(self.mult_temp)]
+ self.mult_temp = random.choice(self.mult)
+ self.rounded[self.mult_temp] = self.rounded[self.dec_answer + 1]
+ del self.mult[self.mult.index(self.mult_temp)]
+ self.mult_temp = random.choice(self.mult)
+ self.rounded[self.mult_temp] = self.rounded[self.dec_temp - 1]
+ del self.mult[self.mult.index(self.mult_temp)]
+ self.mult_temp = random.choice(self.mult)
+ self.rounded[self.mult_temp] = self.rounded[self.dec_temp + 1]
- def show_random_numbers(self, widget, data=None):
- print "INFO: showing random number"
+ def show_random_numbers(self, widget):
+ print "INFO: showing random numbers"
message = "Lower Bound: \t\t\t<b>" + str(self.lower_bound) + "</b>"
message += "\n\nUpper Bound: \t\t\t<b>" + str(self.upper_bound) + "</b>"
message += "\n\nNumber Generated: \t<b>" + str(self.rounded[0]) + "</b>"
message += "\n"
- for item in self.decades:
- message += "\n\nRounded to 10<sup>" + str(int(math.log10(item))) + "</sup>: \t\t<b>" + str(self.rounded[item]) + "</b>"
+ for item in self.rounded:
+ #1message += "\n\nRounded to 10<sup>" + str(int(math.log10(item))) + "</sup>: \t\t<b>" + str(self.rounded[item]) + "</b>"
+ #2message += str(item-1) + ": \t" + str(self.rounded[item-1]) + "\n"
+ #2message += str(item) + ": \t" + str(self.rounded[item]) + "\n"
+ #2message += str(item+1) + ": \t" + str(self.rounded[item+1]) + "\n"
+ message += str(item) + ":\t" + str(self.rounded[item]) + "\n"
self.output.set_markup(message)