# ashbb/shoes_tutorial_html

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
120 lines (88 sloc) 3.75 KB

## Assignment 5 Riddles in Shoes

Create your own Riddles in Shoes by doing the following 5 steps.

1. Open Shoes Window

• Window's width and height are both 400 pixel.
• Can't resize.
• Show your app name and revision number on the window's title bar.
• Color the surface of the window with a horizontal gradation.
2. Lay out titles and elements

• Show title 'Riddles in Shoes'.
• Show line under the title.
• Show subtitles 'Question', 'Answer' and 'Score'.
• Align 10 stars under the line.
3. Show a riddle and create an input answer area

• Click a button to show a riddle at random.
• Use these riddles. (*1)
4. Move down the star

• Click a button to smoothly move down a star for the question.
• If the answer is correct, align the star at the left-bottom.
• If the answer is incorrect, align the star at the right-bottom.
5. Play Riddles in Shoes

• Finish the game after answering all riddles.
• Decorate the surface to your taste.

sample67.png

``````# sample67.rb
Riddles =<<-EOS
What letter is a drink? --> t
What has nothing but a head and a tail? --> coin
What is it that by losing an eye has nothing left but a nose? --> noise
What bird can lift the heaviest weight? --> crane
What is broken when you name it? --> silence
What is a foreign ant? --> important
What lives on its own substance and dies when it devours itself? --> candle
Yesterday is always before today. But there is a place where yesterday always follows today. Where? --> dictionary
How many cookies can you eat on an empty stomach? --> one
What clothing does a house wear? --> address
EOS
Nums = (0..9).sort_by{rand}

Shoes.app :width => 400, :height => 410, :title => 'Riddles r0.5', :resizable => false do
def set_riddle
@num = Nums.pop
@q.text, @a = Riddles.to_a[@num].split(' --> ')
@you.text = nil if @you
end

def set_score s
x = @a.chomp == @you.text ? @i += 25 : @j += 25
s.move x, 390
end

background orange..gold
title 'Riddles in Shoes', :align => 'center'
line 10, 55, 390, 55, :strokewidth => 5
stars = []

subtitle 'Question', :left => 10, :top => 90
@q = tagline '', :left => 20, :top => 130, :width => 360, :stroke => white
set_riddle

subtitle 'Answer', :left => 10, :top => 260
@you = edit_line :left => 20, :top => 310, :width => 200
button 'OK', :left => 225, :top => 310 do
s = stars[@num]
a = animate do |i|
s.move s.left, s.top + i
(a.remove; set_score(s); set_riddle) if s.top > 320
end
end

subtitle 'Score', :left => 10, :top => 340
para 'good job', :left => 10, :top => 380, :width => 100, :stroke => white
para 'how unlucky', :left => 210, :top => 380, :width => 100, :stroke => white
@i, @j = 0, 200

10.times{|i| stars << star(100+ 30*i, 80, 12, 10, 7)}
end
``````

Have fun!

## *1: riddles

What letter is a drink? --> t
What has nothing but a head and a tail? --> coin
What is it that by losing an eye has nothing left but a nose? --> noise
What bird can lift the heaviest weight? --> crane
What is broken when you name it? --> silence
What is a foreign ant? --> important
What lives on its own substance and dies when it devours itself? --> candle
Yesterday is always before today. But there is a place where yesterday always follows today. Where? --> dictionary
How many cookies can you eat on an empty stomach? --> one
What clothing does a house wear? --> address

## Policeman

Ruby 1.9 doesn't have `String#to_a()` method. So, I revised `sample67.rb` a little bit. Now, the sample67.rb works well with Shoes-0.r1263.