[Ruby] Math.. game.. thing 04-29-2015, 02:53 AM
#1
I have no idea what to call this program but it's a game/problem my math teacher used to give us last year. The concept: You need to find a 4 digit number using the numbers 0-9 in the allotted number of tries. If you get one right, you get one more try, get it wrong, you lose one.
It's not my best program and I made it because I got bored in BTT but hey, enjoy!
It's not my best program and I made it because I got bored in BTT but hey, enjoy!
Code:
#by Touka, ©2015
actions = (0..9).to_a
@sequence = []
4.times do |key|
key = actions.sample
@sequence << key
end
@fails_left = gets.to_i
@correct_a = 0
@correct_r = 0
@a = " "
@b = " "
@c = " "
@d = " "
def sel
system "cls"
puts """
__________________________________
/ ___ ___ ___ ___ \\
| | | | | | | | | |
| | #{@a} | | #{@b} | | #{@c} | | #{@d} | |
| |___| |___| |___| |___| |
\\__________________________________/
Tries left: #{@fails_left}
Enter guess (x x x x):"""
guess = gets.chomp
guess = guess.split(" ")
guess = guess.map(&:to_i)
@correct_a_prev = @correct_a
case guess[0]
when @sequence[0]
@correct_a += 1
@a = "#"
when @sequence[1]
@correct_r += 1
when @sequence[2]
@correct_r += 1
when @sequence[3]
@correct_r += 1
end
case guess[1]
when @sequence[0]
@correct_r += 1
when @sequence[1]
@correct_a += 1
@b = "#"
when @sequence[2]
@correct_r += 1
when @sequence[3]
@correct_r += 1
end
case guess[2]
when @sequence[0]
@correct_r += 1
when @sequence[1]
@correct_r += 1
when @sequence[2]
@correct_a += 1
@c = "#"
when @sequence[3]
@correct_r += 1
end
case guess[3]
when @sequence[0]
@correct_r += 1
when @sequence[1]
@correct_r += 1
when @sequence[2]
@correct_r += 1
when @sequence[3]
@correct_a += 1
@d = "#"
end
if @correct_a_prev - @correct_a == 0
@fails_left -= 1
else
hi = " "
end
if @fails_left == 0
system "cls"
puts "you've died. :3"
sleep
else
sel
end
end
selIt's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.















![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)










![[Image: 7ajmN5P.jpg]](https://i.imgur.com/7ajmN5P.jpg)
