diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a09c56d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea diff --git a/.rubocop.yml b/.rubocop.yml index 1004a8e..b173dea 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,4 +3,4 @@ Documentation: Style/FrozenStringLiteralComment: Enabled: false AllCops: - TargetRubyVersion: 2.4.1 + TargetRubyVersion: 2.5.1 diff --git a/Gemfile b/Gemfile index 05a14d1..cb4d5fb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '2.5.1' gem 'rspec' gem 'rubocop' diff --git a/Gemfile.lock b/Gemfile.lock index 4533f5e..712dde8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,34 +1,37 @@ GEM remote: https://rubygems.org/ specs: - ast (2.1.0) - astrolabe (1.3.1) - parser (~> 2.2) - diff-lcs (1.2.5) - parser (2.2.3.0) - ast (>= 1.1, < 3.0) - powerpack (0.1.1) - rainbow (2.0.0) - rspec (3.3.0) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) + ast (2.4.0) + diff-lcs (1.3) + jaro_winkler (1.5.1) + parallel (1.12.1) + parser (2.5.1.2) + ast (~> 2.4.0) + powerpack (0.1.2) + rainbow (3.0.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) - rubocop (0.34.2) - astrolabe (~> 1.3) - parser (>= 2.2.2.5, < 3.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + rubocop (0.59.2) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5, != 2.5.1.1) powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.4) - ruby-progressbar (1.7.5) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.10.0) + unicode-display_width (1.4.0) PLATFORMS ruby @@ -37,5 +40,8 @@ DEPENDENCIES rspec rubocop +RUBY VERSION + ruby 2.5.1p57 + BUNDLED WITH - 1.10.6 + 1.16.6 diff --git a/ball.rb b/ball.rb new file mode 100644 index 0000000..cd1163e --- /dev/null +++ b/ball.rb @@ -0,0 +1,18 @@ +require 'yaml' + +class Ball + ANSWERS = YAML.load_file(File.join(__dir__, './answers.yml')) + GROUP_SIZE = 5 + FOREGROUND_OFFSET = 31 + + def colorize(answer) + color_index = ANSWERS.find_index(answer) / GROUP_SIZE + "\e[#{FOREGROUND_OFFSET + color_index}mANSWER\e[0m" + end + + def shake + answer = ANSWERS.sample + puts colorize(answer) + answer + end +end diff --git a/game.rb b/game.rb new file mode 100644 index 0000000..91c4ddf --- /dev/null +++ b/game.rb @@ -0,0 +1,26 @@ +require_relative './pet' + +class Game + def initialize + p 'Hello, lets play)' + p 'Put the name of your dog' + name = gets.chomp + @pet = Pet.new(name) + + choose_action + end + + def choose_action + action = gets.chomp + + if @pet.respond_to? action + @pet.public_send(action) + else + p 'sorry there no such action, try put `help`' + end + + choose_action + end +end + +Game.new diff --git a/pet.rb b/pet.rb new file mode 100644 index 0000000..e9c970c --- /dev/null +++ b/pet.rb @@ -0,0 +1,116 @@ +class Pet + def initialize(name) + @name = name + @type = 'DOG' + @lives = 5 + @stuff_in_belly = 10 + @stuff_in_intestine = 0 + @tired = 0 + @mood = 'NORMAL' + @ruby_skill = 0 + @js_skill = 0 + + p "#{@name} was born" + end + + def help + p 'Here all available commands:' + p 'name => display pet name' + p 'study_ruby => learn Ruby language' + p 'study_js => learn JS language' + p 'walk => reset poop' + p 'put_to_bed => reset tired' + p 'just_watch => do nothing' + end + + def info + p "Name: #{@name}" + p "Hungry: #{hungry?}" + p "Poopy: #{poopy?}" + p "JS: #{poopy?}" + end + + def feed + @stuff_in_belly = 10 + p 'I`m full' + passage_of_time + end + + def study_ruby + if @tired < 10 + @ruby_skill += 1 + p 'Wow. Ruby is awesome!' + + if @ruby_skill == 10 + puts 'looks at you like a piece of shit' + exit + end + passage_of_time + end + end + + def study_js + if @tired < 10 + @js_skill += 1 + p 'I love JS!' + + if @js_skill == 10 + p 'looks at you like a piece of shit' + exit + end + + passage_of_time + end + end + + def walk + p 'Waaaaaaalk!' + @stuff_in_intestine = 0 + passage_of_time + end + + def put_to_bed + p 'Good night' + @tired = 0 + + passage_of_time + end + + def just_watch + p 'I`m boring, lets do something?' + passage_of_time + end + + private + + def passage_of_time + @stuff_in_belly -= 1 + @stuff_in_intestine += 1 + + if hungry + if @stuff_in_belly == 0 + p 'i live you' + exit + else + p 'I m hungry' + end + end + + if poopy + if @stuff_in_intestine == 10 + p 'Oops' + @stuff_in_intestine = 0 + else + p 'Wanna poop' + end + end + end + + def hungry + @stuff_in_belly <= 2 + end + + def poopy + @stuff_in_intestine >= 8 + end +end diff --git a/spec/pet_spec.rb b/spec/pet_spec.rb new file mode 100644 index 0000000..54bd83a --- /dev/null +++ b/spec/pet_spec.rb @@ -0,0 +1,39 @@ +require 'yaml' +require_relative '../pet' + +RSpec.describe Pet do + let(:pet) { Pet.new('Pushka') } + + it 'Should check js_skill inc' do + expect(pet.instance_variable_get('@js_skill')).to eql(0) + pet.study_js + expect(pet.instance_variable_get('@js_skill')).to eql(1) + end + it 'Should check ruby_skill inc' do + expect(pet.instance_variable_get('@ruby_skill')).to eql(0) + pet.study_ruby + expect(pet.instance_variable_get('@ruby_skill')).to eql(1) + end + it 'Should don`t inc ruby_skill if tired' do + pet.instance_variable_set('@tired', 10) + pet.study_ruby + expect(pet.instance_variable_get('@ruby_skill')).to eql(0) + end + + it 'should fill `@stuff_in_belly` on `feed`' do + pet.instance_variable_set('@stuff_in_belly', 5) + pet.feed + expect(pet.instance_variable_get('@stuff_in_belly')).to eql(9) + end + + it 'should reset tired if put_to_bed' do + pet.instance_variable_set('@tired', 5) + pet.put_to_bed + expect(pet.instance_variable_get('@tired')).to eql(0) + end + it 'should reset @stuff_in_intestine if walk' do + pet.instance_variable_set('@stuff_in_intestine', 5) + pet.walk + expect(pet.instance_variable_get('@stuff_in_intestine')).to eql(1) + end +end