Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'sqlite3'
- @db = SQLite3::Database.new( "game.sqlite3" )
- def get_current_counter
- current = @db.execute( 'select current from counter limit 1' )
- current.each { |c| @counter = c[0].to_i }
- end
- def increment_counter
- @counter = @counter + 1
- @db.execute('update counter set current=' + @counter.to_s)
- end
- def increment_thinker
- @next_think = Time.now.to_f + 0.1
- end
- def think
- get_current_counter
- increment_counter
- increment_thinker
- @go = @counter < 100
- end
- def think_time?
- Time.now.to_f >= @next_think
- end
- #########
- increment_thinker
- @go = true
- while @go
- if think_time? then
- Thread.new do think end
- else
- sleep(@next_think - Time.now.to_f)
- end
- end
Add Comment
Please, Sign In to add comment