Created
September 25, 2014 13:47
-
-
Save MichaelHoste/cc314094f86e4648fa05 to your computer and use it in GitHub Desktop.
Hackety-Hack interactive hangman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def circle(size) | |
for i in (1...360) | |
forward size | |
turnright 1 | |
end | |
end | |
def draw_gallows | |
goto 150, 300 | |
setheading 270 | |
forward 150 | |
turnleft 180 | |
forward 25 | |
turnright 90 | |
forward 200 | |
turnleft 90 | |
forward 70 | |
turnleft 90 | |
forward 20 | |
end | |
def draw_head | |
goto 184, 141 | |
setheading 0 | |
circle 0.35 | |
end | |
def draw_body | |
goto 204, 159 | |
setheading 0 | |
turnleft 180 | |
forward 60 | |
end | |
def draw_left_arm | |
goto 204, 189 | |
setheading 55 | |
forward 35 | |
end | |
def draw_right_arm | |
goto 204, 189 | |
setheading -55 | |
forward 35 | |
end | |
def draw_left_leg | |
goto 204, 219 | |
setheading 130 | |
forward 40 | |
end | |
def draw_right_leg | |
goto 204, 219 | |
setheading -130 | |
forward 40 | |
end | |
Turtle.draw do | |
#para "Hangman Game" | |
draw_gallows | |
letters = [] | |
word = ['salut', 'bonjour', 'supercalifragilisticexpialidiosius'].sample | |
errors = 0 | |
para ('-' * word.size + "\n") | |
keypress do |letter| | |
letters << letter | |
if not word.include? letter | |
errors = errors + 1 | |
draw_head if errors == 1 | |
draw_body if errors == 2 | |
draw_left_arm if errors == 3 | |
draw_right_arm if errors == 4 | |
draw_left_leg if errors == 5 | |
draw_right_leg if errors == 6 | |
end | |
display_word = word | |
word.each_char do |letter| | |
if not letters.include?(letter) | |
display_word = display_word.gsub(letter, '-') | |
end | |
end | |
para "#{display_word}\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment