Skip to content

Weekend challenge - #2127

Open
michaelcychan wants to merge 13 commits into
makersacademy:mainfrom
michaelcychan:main
Open

Weekend challenge#2127
michaelcychan wants to merge 13 commits into
makersacademy:mainfrom
michaelcychan:main

Conversation

@michaelcychan

Copy link
Copy Markdown

Completed the basic and multi player functions.

@penguat penguat left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, well done!

Comment thread .gitignore
# Local cache of Rubocop remote config
.rubocop-*

capybara-*.html

Copy link
Copy Markdown

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!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea

Comment thread app.rb
erb(:game)
end

get '/player_2' do

Copy link
Copy Markdown

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?

Copy link
Copy Markdown

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.

Comment thread spec/show_results_spec.rb

describe '#match' do
it 'declares Player 1 wins' do
expect(player1).to receive(:choice).and_return(:rock).at_most(3).times

Copy link
Copy Markdown

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

Comment thread .gitignore
# Local cache of Rubocop remote config
.rubocop-*

capybara-*.html

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea

Comment thread config.ru

require_relative "./app"

run RPS No newline at end of file

Copy link
Copy Markdown

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

Comment thread app.rb
erb(:game)
end

get '/player_2' do

Copy link
Copy Markdown

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.

Comment thread lib/player.rb

class Player
attr_reader :name
attr_accessor :choice

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of attr!

Comment thread lib/player.rb
end

def throw
@choice = [:rock, :scissors, :paper].sample

Copy link
Copy Markdown

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.

Comment thread lib/game.rb
def player_2
@players[1]
end

Copy link
Copy Markdown

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

Comment thread lib/game.rb
@other_player = @players[1]

@declaration = ""
@players_num = players_num

Copy link
Copy Markdown

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.

Comment thread lib/game.rb Outdated
end

def declaration
@declaration

Copy link
Copy Markdown

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

Comment thread lib/game.rb Outdated
if @winner == nil
@declaration = "It is a tie!"
elsif players_num == 2
@declaration = "#{@winner.name} wins!"

Copy link
Copy Markdown

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

Comment thread views/index.erb
<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">

Copy link
Copy Markdown

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