Login Register


[Ruby] Math.. game.. thing filter_list
Author
Message
[Ruby] Math.. game.. thing #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!

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 sel
It'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.

Reply





Messages In This Thread
[Ruby] Math.. game.. thing - by Inori - 04-29-2015, 02:53 AM
RE: [Ruby] Math.. game.. thing - by Oni - 04-29-2015, 04:27 PM
RE: [Ruby] Math.. game.. thing - by Dyme - 04-29-2015, 05:20 PM
RE: [Ruby] Math.. game.. thing - by Inori - 04-29-2015, 08:14 PM



Users browsing this thread: