Hi all, in an effort to learn Ruby (and Shoes), I have made a simplistic
'Infinite Monkeys' type program (as seen below - and yes, I know it can be
made a lot simpler than that)
What I want, is to create a shoes app that has a few colored squares which
are initially red, they will each run thier own instance of Infinite Monkeys
and turn green when a 'monkey' types the correct sequence, the problem is
getting the boxes to turn green when @@ordered is true, any help would be
greatly appreciated,
Trent

class Monkeys
    def Typing(a)
        sequence=Array.new(a)

        #Simulates the monkey typing in 'a' numbers
        for i in 0..a-1
            sequence[i]=(rand*a+1).to_i
        end

        #Checks to see if the numbers are all in order.
        @@ordered=true
        for j in 0..a-1
            if sequence[j]!=j+1
                @@ordered=false
                @@monkeys += 1
            end
        end
    end

    def Run()
        @@ordered=false

        #a=gets.to_i

        #Loop until a 'monkey' types the correct sequence
        while (@@ordered==false)
            #Uncomment a=gets.to_i and replace 5 with a if you want the user
to input sequence length
            @@test.Typing(5)
        end

        #puts "It took "+@@monkeys.to_s+" monkeys"
    end
end

@@test=Monkeys.new
@@test.Run()

Reply via email to