Skip to content
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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

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!

@@ -3,3 +3,5 @@

# 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

@@ -3,3 +3,5 @@

# 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

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.

None yet

3 participants