![]() |
|
[Ruby] Math.. game.. thing - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: [Ruby] Math.. game.. thing (/Thread-Ruby-Math-game-thing) |
[Ruby] Math.. game.. thing - Inori - 04-29-2015 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! 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
selRE: [Ruby] Math.. game.. thing - Oni - 04-29-2015 Ruby might need its own section soon. RE: [Ruby] Math.. game.. thing - Dyme - 04-29-2015 (04-29-2015, 04:27 PM)Oni Wrote: Ruby might need its own section soon. I think you mean "@Touka might need his own section soon"
RE: [Ruby] Math.. game.. thing - Inori - 04-29-2015 (04-29-2015, 04:27 PM)Oni Wrote: Ruby might need its own section soon. (04-29-2015, 05:20 PM)Dyme Wrote: I think you mean "@Touka might need his own section soon" I'm okay with either of these |