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

RE: [Ruby] Math.. game.. thing #2
Ruby might need its own section soon.
[Image: 7ajmN5P.jpg]

Telegram: Oni_SL (Link)

[+] 1 user Likes Oni's post
Reply

RE: [Ruby] Math.. game.. thing #3
(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"

[Image: FRQWPda.png]

[+] 3 users Like Dyme's post
Reply

RE: [Ruby] Math.. game.. thing #4
(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
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.

[+] 1 user Likes Inori's post
Reply







Users browsing this thread: 1 Guest(s)