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

Jimmy Lyons RPS challenge #2119

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

Conversation

jimmy-lyons
Copy link

Completed the basic functionality (with no frills).

Copy link

@lukestorey95 lukestorey95 left a comment

Choose a reason for hiding this comment

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

A good starting point, but I think if you wanted to move onto some more complex functionality it might be hard considering the current use of a single class model, and global variables. With some refactoring and splitting the Game class that would leave the code in much better condition, and make it easier to add multiplayer functionality etc.

I have some thoughts on the use of symbols vs strings, but really liked your use of output array in the spec to test multiple outcomes in one test - very neat

end
end

describe '# return_winner' do

Choose a reason for hiding this comment

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

Add tests for all possible outcomes, as only three are tested here


subject(:game) { Game.new('rock') }

it 'creates instances of game' do

Choose a reason for hiding this comment

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

describe Game tests that there is a Game class and that it can be initialised so don't think you need this test as well

end

def has_expected_output
outputs = ['Computer Wins!', 'Player Wins!', 'Draw']

Choose a reason for hiding this comment

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

Nice use of an array for outputs rather than expecting on multiple individual strings - I hadn't though to do that

end

post '/names' do
$player_name = params[:name]

Choose a reason for hiding this comment

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

Global variables are apparently evil - player should be split out into separate class to be injected into Game


def initialize(choice)
@player_action = choice
@pairs = { rock: 'paper', paper: 'scissors', scissors: 'rock' }

Choose a reason for hiding this comment

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

Think this is for the return_winner method, so why is it stored as an instance variable for the class?

end

def random_choice
['rock', 'paper', 'scissors'].sample

Choose a reason for hiding this comment

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

Could store this as a constant as the three options won't change. Also consider using symbols as they are immutable and are an identifier of an action rather than a typed user input.

<h1>Pick an action <%=$player_name%>:</h1>

<form action='/choice' method='post'>
<input type="radio" id="rock" name="choice" value="Rock">

Choose a reason for hiding this comment

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

Why set value to 'Rock' when you then use value.downcase in the app to convert to lowercase? Could refactor that out

end

post '/choice' do
$player_choice = params[:choice].downcase

Choose a reason for hiding this comment

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

You're using a button input in the form so the choice shouldn't= need to use .downcase

end

get '/result' do
game = Game.new($player_choice)

Choose a reason for hiding this comment

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

Consider initialising the Game when the choice is created so that you can store the choice within a player and within the Game and avoid the evil global variables

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

2 participants