mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Move more prints into functions
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
def print_introduction
|
def say_introduction
|
||||||
puts " " * 33 + "HURKLE"
|
puts " " * 33 + "HURKLE"
|
||||||
puts " " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
puts " " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||||
3.times { puts }
|
3.times { puts }
|
||||||
@@ -18,7 +18,7 @@ def print_introduction
|
|||||||
end
|
end
|
||||||
|
|
||||||
def main
|
def main
|
||||||
print_introduction
|
say_introduction
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
$a = rand($g).floor
|
$a = rand($g).floor
|
||||||
@@ -29,25 +29,19 @@ def main
|
|||||||
print "? "
|
print "? "
|
||||||
x, y = gets.chomp.split(",").map(&:to_i)
|
x, y = gets.chomp.split(",").map(&:to_i)
|
||||||
if (x-$a).abs + (y-$b).abs == 0
|
if (x-$a).abs + (y-$b).abs == 0
|
||||||
you_found_him(k)
|
say_success(k)
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
say_where_to_go(x, y)
|
say_where_to_go(x, y)
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
if not found
|
say_failure if not found
|
||||||
puts
|
say_play_again
|
||||||
puts "SORRY, THAT'S " + $n.to_s + " GUESSES."
|
|
||||||
puts "THE HURKLE IS AT " + $a.to_s + "," + $b.to_s
|
|
||||||
end
|
|
||||||
puts
|
|
||||||
puts "LET'S PLAY AGAIN, HURKLE IS HIDING."
|
|
||||||
puts
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def you_found_him(k)
|
def say_success(k)
|
||||||
puts
|
puts
|
||||||
puts "YOU FOUND IT IN " + k.to_s + " GUESSES!"
|
puts "YOU FOUND IT IN " + k.to_s + " GUESSES!"
|
||||||
end
|
end
|
||||||
@@ -59,4 +53,16 @@ def say_where_to_go(x, y)
|
|||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def say_failure
|
||||||
|
puts
|
||||||
|
puts "SORRY, THAT'S " + $n.to_s + " GUESSES."
|
||||||
|
puts "THE HURKLE IS AT " + $a.to_s + "," + $b.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def say_play_again
|
||||||
|
puts
|
||||||
|
puts "LET'S PLAY AGAIN, HURKLE IS HIDING."
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|||||||
Reference in New Issue
Block a user