-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Simon Tinsley #2118
Open
simon-2357
wants to merge
2
commits into
makersacademy:main
Choose a base branch
from
simon-2357:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Simon Tinsley #2118
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'sinatra/base' | ||
require 'sinatra/reloader' | ||
require_relative 'lib/game' | ||
|
||
class RPS < Sinatra::Base | ||
enable :sessions | ||
|
||
configure :development do | ||
register Sinatra::Reloader | ||
end | ||
|
||
get "/" do | ||
erb :index | ||
end | ||
|
||
post '/name' do | ||
$player_name = params[:name] | ||
redirect '/play' | ||
end | ||
|
||
get '/play' do | ||
@player_name = $player_name | ||
erb :play | ||
end | ||
|
||
get '/rock' do | ||
@player_name = $player_name | ||
$result = Game.new.rock | ||
redirect '/result' | ||
end | ||
|
||
get '/paper' do | ||
@player_name = $player_name | ||
$result = Game.new.paper | ||
redirect '/result' | ||
end | ||
|
||
get '/scissors' do | ||
@player_name = $player_name | ||
$result = Game.new.scissors | ||
redirect '/result' | ||
end | ||
|
||
get '/result' do | ||
@result = $result | ||
erb :result | ||
end | ||
|
||
run! if app_file == $0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require_relative './app' | ||
run RPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class Game | ||
|
||
def initialize(move = rand(3)) | ||
@comp_move = move | ||
end | ||
|
||
def rock | ||
if @comp_move.zero? | ||
"It's a draw! You picked rock and so did the computer." | ||
elsif @comp_move == 1 | ||
"Sorry, you lose! You picked rock and the computer picked paper." | ||
else | ||
"Congratulations, you won! You picked rock and the computer picked scissors." | ||
end | ||
end | ||
|
||
def paper | ||
if @comp_move == 1 | ||
"It's a draw! You picked paper and so did the computer." | ||
elsif @comp_move == 2 | ||
"Sorry, you lose! You picked paper and the computer picked scissors." | ||
else | ||
"Congratulations, you won! You picked paper and the computer picked rock." | ||
end | ||
end | ||
|
||
def scissors | ||
if @comp_move == 2 | ||
"It's a draw! You picked scissors and so did the computer." | ||
elsif @comp_move == 1 | ||
"Congratulations, you won! You picked scissors and the computer picked paper." | ||
else | ||
"Sorry, you lose! You picked scissors and the computer picked rock." | ||
end | ||
end | ||
end | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
body {background-color: #f0f0f0; font-family: Arial, Helvetica, sans-serif;} | ||
h1 {font-size: 48px; margin-bottom: 16px;} | ||
.container {max-width: 1200px; text-align: center; background-color: #fff; margin: 40px auto 0 auto; padding: 20px; border-radius: 10px} | ||
button {background-color: #072a6c; color: #fff; border-radius: 10px; padding: 10px 30px; margin: 10px; border: 0} | ||
p {margin-bottom: 16px;} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dude - this is a triumph of simple elegant styling - nice work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
feature "Player can play RPS" do | ||
scenario "Player enters their name" do | ||
enter_name | ||
expect(page).to have_text 'Simon' | ||
end | ||
|
||
scenario "I select rock and I'm told I've won" do | ||
allow_any_instance_of(Game).to receive(:move).and_return(2) # Can't get this to stub out randomness in the tests | ||
enter_name | ||
click_link "Rock" | ||
expect(page).to have_content("Congratulations, you won! You picked rock and the computer picked scissors.") | ||
end | ||
|
||
scenario "I select scissors and I'm told it's a draw" do | ||
allow_any_instance_of(Game).to receive(:move).and_return(2) | ||
enter_name | ||
click_link "Scissors" | ||
expect(page).to have_content("It's a draw! You picked scissors and so did the computer.") | ||
end | ||
|
||
scenario "I select paper and I'm told it's a loss" do | ||
allow_any_instance_of(Game).to receive(:move).and_return(2) | ||
enter_name | ||
click_link "Paper" | ||
expect(page).to have_text("Sorry, you lose! You picked paper and the computer picked scissors.") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def enter_name | ||
visit("/") | ||
fill_in 'name', with: 'Simon' | ||
click_on "I'm ready" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'game' | ||
|
||
describe Game do | ||
|
||
let(:computer_scissors) { Game.new(2) } | ||
let(:computer_rock) { Game.new(0) } | ||
let(:computer_paper) { Game.new(1) } | ||
|
||
describe '#rock' do | ||
context 'computer move is paper' do | ||
it 'returns a losing message' do | ||
expect(computer_paper.rock).to eq "Sorry, you lose! You picked rock and the computer picked paper." | ||
end | ||
end | ||
|
||
context 'computer move is rock' do | ||
it 'returns a drawing message' do | ||
expect(computer_rock.rock).to eq "It's a draw! You picked rock and so did the computer." | ||
end | ||
end | ||
|
||
context 'computer move is scissors' do | ||
it 'returns a winning message' do | ||
expect(computer_scissors.rock).to eq "Congratulations, you won! You picked rock and the computer picked scissors." | ||
end | ||
end | ||
end | ||
|
||
describe '#paper' do | ||
context 'computer move is paper' do | ||
it 'returns a drawing message' do | ||
expect(computer_paper.paper).to eq "It's a draw! You picked paper and so did the computer." | ||
end | ||
end | ||
|
||
context 'computer move is rock' do | ||
it 'returns a winning message' do | ||
expect(computer_rock.paper).to eq "Congratulations, you won! You picked paper and the computer picked rock." | ||
end | ||
end | ||
|
||
context 'computer move is scissors' do | ||
it 'returns a losing message' do | ||
expect(computer_scissors.paper).to eq "Sorry, you lose! You picked paper and the computer picked scissors." | ||
end | ||
end | ||
end | ||
|
||
describe '#scissors' do | ||
context 'computer move is paper' do | ||
it 'returns a winning message' do | ||
expect(computer_paper.scissors).to eq "Congratulations, you won! You picked scissors and the computer picked paper." | ||
end | ||
end | ||
|
||
context 'computer move is rock' do | ||
it 'returns a losing message' do | ||
expect(computer_rock.scissors).to eq "Sorry, you lose! You picked scissors and the computer picked rock." | ||
end | ||
end | ||
|
||
context 'computer move is scissors' do | ||
it 'returns a drawing message' do | ||
expect(computer_scissors.scissors).to eq "It's a draw! You picked scissors and so did the computer." | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<head> | ||
<link rel="stylesheet" href="/style.css"> | ||
</head> | ||
<div class="container"> | ||
<h1>Welcome to Rock, Paper, Scissors!</h1> | ||
|
||
<h2>Enjoy some hard earned down time after your strenuous marketing activities.</h2> | ||
|
||
<form action="/name" method="post"> | ||
<p><label for="name">Please enter your name:</label></p> | ||
<input id="name" type="text" name="name"> | ||
<input type="submit" value="I'm ready!"> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<head> | ||
<link rel="stylesheet" href="/style.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="container"><h1> Welcome <%= @player_name %> </h1> | ||
|
||
<h2> Please choose your move </h2> | ||
|
||
<a href="/rock"><button id="rock">Rock</button></a> | ||
<a href="/paper"><button id="paper">Paper</button></a> | ||
<a href="/scissors"><button id="scissors">Scissors</button></a> | ||
</div> | ||
</body> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lovely work - elegant routing and selfishly it answers the question I was stuck on. Nice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<head> | ||
<link rel="stylesheet" href="/style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<%= @result %> | ||
|
||
<a href ="/play"> | ||
<button>Play again</button> | ||
</a> | ||
</div> | ||
</body> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 like how simple this is to follow - it's a nice way to have implemented the logic - nice work.