Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker. The code-maker, which will be played by the application we’re going to write, creates a secret code of four numbers between 1 and 6.
Add this line to your application's Gemfile:
gem'codebreaker',:git=>"git://github.com/gremax/codebreaker"And then execute:
$ bundle
Start an example console game:
$ bundle --binstubs
$ bundle exec bin/codebreaker
Or write own:
require"bundler/setup"require"codebreaker"Attempts=10game=Codebreaker::Game.new(Attempts)game.startloopdoputs"\nEnter guess (? for help):"guess=gets.chompcaseguesswhen"hint"putsgame.hintwhen"start"game.startwhen"scores"beginputs"Score table:".underlinegame.scores.eachdo |s|
puts"/ #{s.username} / Attempts: #{s.attempts} / Time: #{(s.finish_at - s.start_at).to_i}s."endrescue=>eputseendwhen""exitelsebeginsubmit=game.submit(guess)rescue=>eputsenextendputssubmitifsubmit == "Game over" || submit == "++++"puts"\nSave your score? (y/n)"casegets.chompwhen"y"puts"Enter username:"game.save(gets.chomp)endputs"\nRestart Codebreaker? (y/n)"casegets.chompwhen"y"game.startwhen"n"puts"Bye!"exitendendendend$ bundle exec rspec
Or
$ bundle exec rake
$ rake -T db
rake db:remove # Remove database file
rake db:reset # Reset database- Fork it ( https://github.com/gremax/codebreaker/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request