-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Weekend challenge #2127
base: main
Are you sure you want to change the base?
Weekend challenge #2127
Conversation
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.
Excellent work, well done!
@@ -3,3 +3,5 @@ | |||
|
|||
# Local cache of Rubocop remote config | |||
.rubocop-* | |||
|
|||
capybara-*.html |
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.
I love this, you've saved yourself some work here!
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.
Great idea
erb(:game) | ||
end | ||
|
||
get '/player_2' do |
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.
Could this be broken up? It feels like a lot of logic in the controller here.
Maybe each condition body (between the if/else and end) could be its own method?
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.
I agree; this looks like sound logic, but I would suggest separating the two conditions within the IF statement and considering separating the redirect and view statements into separate routes.
|
||
describe '#match' do | ||
it 'declares Player 1 wins' do | ||
expect(player1).to receive(:choice).and_return(:rock).at_most(3).times |
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.
This is a lovely clear test
@@ -3,3 +3,5 @@ | |||
|
|||
# Local cache of Rubocop remote config | |||
.rubocop-* | |||
|
|||
capybara-*.html |
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.
Great idea
|
||
require_relative "./app" | ||
|
||
run RPS |
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.
Minor issue: Add a code syntax checker to your text editor to check syntax issues
erb(:game) | ||
end | ||
|
||
get '/player_2' do |
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.
I agree; this looks like sound logic, but I would suggest separating the two conditions within the IF statement and considering separating the redirect and view statements into separate routes.
|
||
class Player | ||
attr_reader :name | ||
attr_accessor :choice |
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.
Great use of attr!
end | ||
|
||
def throw | ||
@choice = [:rock, :scissors, :paper].sample |
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.
Point of consideration: Your implementation works, which is excellent and the most important thing; however, you are not using the symbol object here. I would suggest sticking to string objects within an array for this challenge.
def player_2 | ||
@players[1] | ||
end | ||
|
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.
winner, player_1 and player_2 can be refactored into attr
objects
@other_player = @players[1] | ||
|
||
@declaration = "" | ||
@players_num = players_num |
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.
I think this construction could be refactored and simplified.
lib/game.rb
Outdated
end | ||
|
||
def declaration | ||
@declaration |
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.
not necessary as you have attr'd it above
lib/game.rb
Outdated
if @winner == nil | ||
@declaration = "It is a tie!" | ||
elsif players_num == 2 | ||
@declaration = "#{@winner.name} wins!" |
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.
I don't think the declaration variable is needed, this can be inputted directly into the view
<p>Before we start...</p> | ||
<form action="/game" method="post"> | ||
<p>Please choose number of players:</p> | ||
<p><input type="radio" id="1" name="players_num" value="1"> |
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.
Great use of radio buttons
Completed the basic and multi player functions.