Created
March 21, 2013 22:13
-
-
Save kirel/5217281 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # coding: utf-8 | |
| require 'awesome_print' | |
| words = %w[bla blub] | |
| letters = words.sample.split('') # get a random word | |
| solution = letters.size.times.map { '_' } | |
| lifes = 10 | |
| def draw(lifes, solution) | |
| puts "#{lifes} Leben übrig" | |
| puts solution.join(' ') | |
| puts | |
| end | |
| # clear screen with puts "\e[H\e[2J" | |
| puts 'Welches Wort ist gesucht?' | |
| puts 'Tippe "ende" um das Spiel zu beenden' | |
| puts 'Tippe einen Buchstaben!' | |
| draw(lifes, solution) | |
| while (typed = gets) && lifes > 0 && | |
| typed.strip! | |
| break if typed == 'ende' | |
| found = false | |
| letters.each_with_index do |letter, index| | |
| if letter == typed | |
| found = true | |
| solution[index] = typed | |
| end | |
| end | |
| if found | |
| puts 'Treffer!' | |
| else | |
| lifes -= 1 | |
| puts 'Ouch! War nicht dabei... :(' | |
| end | |
| draw(lifes, solution) | |
| break if solution == letters | |
| puts 'Tippe einen Buchstaben!' | |
| puts | |
| end | |
| if solution == letters | |
| puts 'Gaturliere! Du hast gewonnen!' | |
| else | |
| puts 'Leider verloren :(' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment