-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath-a-Cora.rb
45 lines (33 loc) · 1.01 KB
/
Math-a-Cora.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Shoes.app :width => 400, :height => 700, :title => "Math-a-Cora" do
# App setup
@name = ask "What's Your Name?"
stack :align => "center" do
para "Hello #{@name}!", :align => "center", :size => "xx-large"
@the_problem = para "", :align => "center", :size => "x-large"
@the_answer = "into the void..."
@the_entry = edit_line "", :width => 390
end
stack :align => "center" do
@the_entry.change do |entry|
solved! if @the_entry.text == @the_answer
end
end
@new_problem = button "Try Another" do |btn|
new_problem
end
@image = image :align => "center", :width => 380, :margin_left => "10px"
# Helpers
def new_problem
@the_problem.text = "#{rand(5) + 1} + #{rand(5) + 1}"
@the_problem.stroke = black
@the_answer = eval(@the_problem.text).to_s
@the_entry.text = ""
@image.path = ""
end
def solved!
@the_problem.stroke = green
@image.path = File.expand_path("~/.hacketyhack/pics/cora.jpg")
end
# Startup
new_problem
end