Skip to content

Conversation

michaelcychan
Copy link

Completed the basic and multi player functions.

Copy link

@penguat penguat left a 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!

# Local cache of Rubocop remote config
.rubocop-*

capybara-*.html
Copy link

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!

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
Copy link

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?

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
Copy link

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

# Local cache of Rubocop remote config
.rubocop-*

capybara-*.html

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 No newline at end of file

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

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

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

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

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

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

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!"

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">

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants