-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lesson #2 #2
Open
somenickname
wants to merge
2
commits into
geekhub-rails:master
Choose a base branch
from
somenickname:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Lesson #2 #2
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
ruby '2.3.1' | ||
ruby '2.5.1' | ||
|
||
gem 'rspec' | ||
gem 'rubocop' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect { pet.study_js }.to change(pet.instance_variable(@js_skill)).form(0).to(1)