-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
70 lines (63 loc) · 1.55 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Wisielec
def initialize
@word = words.sample
@chances = 5
@word_blank = ""
@word.first.size.times do
@word_blank += "_ "
end
end
def words
[
["kontynent","Geografia"],
["terrorysta","Zawód"],
["onomatopeja","Środki stylistyczne"],
["gitara","Instrumenty muzyczne"],
["serce","Organy wewnętrzne"],
["zupa","Dania"]
]
end
def word_blank last_guess = nil
blank_update(last_guess) unless last_guess.nil?
puts @word_blank
end
def blank_update last_guess
new_space = @word_blank.split
new_space.each_with_index do |letter, index|
if letter == '_' && @word.first[index] == last_guess
new_space[index] = last_guess
end
end
@word_blank = new_space.join(' ')
end
def begin
puts "Nowa gra, twoja kategoria to: #{@word.last}"
puts "Twoje słowo ma #{@word.first.size} liter"
word_blank
guessing
end
def guessing
if @chances > 0
puts "Wprowadź literę:"
guess = gets.chomp
correct = @word.first.include? guess
if correct
puts "Prawidłowa litera"
word_blank guess
if @word.first == @word_blank.split.join
puts "Gratulacje, wygrałeś!"
else
guessing
end
else
@chances -=1
puts "Zła litera, zostało ci : #{@chances} szans. Spróbuj ponownie"
guessing
end
else
puts "Przegrałeś"
end
end
end
game = Wisielec.new
game.begin