-
Notifications
You must be signed in to change notification settings - Fork 250
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
Friday finish #259
Open
erb16
wants to merge
4
commits into
makersacademy:main
Choose a base branch
from
erb16: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
Friday finish #259
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,53 @@ | ||
require 'sinatra/base' | ||
require './lib/player' | ||
# require "sinatra/reloader" if development? | ||
class RockPaperScissors < Sinatra::Base | ||
get '/test' do | ||
'test page' | ||
|
||
enable :sessions | ||
|
||
# get '/test' do | ||
# 'test page' | ||
# end | ||
|
||
get '/' do | ||
erb(:index) | ||
end | ||
|
||
post '/submit-name' do | ||
session["player_name"] = params["player_name"] | ||
erb(:results) | ||
end | ||
|
||
# get '/results' do | ||
# @player_name = session["player_name"] | ||
|
||
# erb(:results) | ||
# end | ||
|
||
get '/rock' do | ||
player = Player.new | ||
$pc_plays = player.pc_plays | ||
$player_plays = "rock" | ||
$result = player.rock | ||
erb(:rock) | ||
end | ||
|
||
get '/paper' do | ||
player = Player.new | ||
$pc_plays = player.pc_plays | ||
$player_plays = "paper" | ||
$result = player.paper | ||
erb(:rock) | ||
end | ||
|
||
get '/scissors' do | ||
player = Player.new | ||
$pc_plays = player.pc_plays | ||
$player_plays = "scissors" | ||
$result = player.scissors | ||
erb(:rock) | ||
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
require_relative './app' | ||
|
||
run RockPaperScissors | ||
|
||
|
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,46 @@ | ||
class Player | ||
def pc_plays | ||
@pc_plays = %w(rock paper scissors).sample | ||
# return @pc_plays | ||
end | ||
|
||
def rock | ||
if $pc_plays == "scissors" | ||
$gameplay = "You win!" | ||
# return $gameplay | ||
elsif $pc_plays == "paper" | ||
$gameplay = "You lose!" | ||
# return $gameplay | ||
elsif $pc_plays == "rock" | ||
$gameplay = "It's a tie!" | ||
# return $gameplay | ||
end | ||
end | ||
|
||
def scissors | ||
if $pc_plays == "scissors" | ||
$gameplay = "It's a tie!" | ||
# return $gameplay | ||
elsif $pc_plays == "paper" | ||
$gameplay = "You win!" | ||
# return $gameplay | ||
elsif $pc_plays == "rock" | ||
$gameplay = "You lose! :(" | ||
# return $gameplay | ||
end | ||
end | ||
|
||
def paper | ||
if $pc_plays == "scissors" | ||
$gameplay = "You lose!" | ||
return $gameplay | ||
elsif $pc_plays == "paper" | ||
$gameplay = "It's a tie!" | ||
return $gameplay | ||
elsif $pc_plays == "rock" | ||
$gameplay = "You win!" | ||
return $gameplay | ||
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 @@ | ||
describe '#name' do | ||
xit 'returns the name' do | ||
expect(Bob.name).to eq 'Bob' | ||
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,9 @@ | ||
feature 'Choose rock weapon' do | ||
scenario 'clicking on rock button' do | ||
visit('/submit-name') | ||
fill_in :player_1_name, with: 'Bob' | ||
click_button 'Submit' | ||
click_button 'ROCK' | ||
expect(page).to have_content 'rock' | ||
end | ||
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. Great capybara test format |
||
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,8 @@ | ||
feature 'Enter names' do | ||
scenario 'submitting name' do | ||
visit('/') | ||
fill_in :player_name, with: 'Bob' | ||
click_button 'Submit' | ||
expect(page).to have_content 'Bob' | ||
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,69 @@ | ||
describe Player do | ||
it "chooses a pc weapon at random" do | ||
player = Player.new | ||
expect(['rock', 'paper', 'scissors']).to include(player.pc_plays) | ||
end | ||
|
||
|
||
context "when player chooses rock" do | ||
it "correctly identifies win" do | ||
player = Player.new | ||
$pc_plays = "scissors" | ||
expect(player.rock).to eq "You win!" | ||
end | ||
|
||
it "correctly identifies lost" do | ||
player = Player.new | ||
$pc_plays = "paper" | ||
expect(player.rock).to eq "You lose!" | ||
end | ||
|
||
it "correctly identifies draw" do | ||
player = Player.new | ||
$pc_plays = "rock" | ||
expect(player.rock).to eq "It's a tie!" | ||
end | ||
end | ||
|
||
context "when player chooses scissors" do | ||
it "correctly identifies win" do | ||
player = Player.new | ||
$pc_plays = "paper" | ||
expect(player.scissors).to eq "You win!" | ||
end | ||
|
||
it "correctly identifies lost" do | ||
player = Player.new | ||
$pc_plays = "rock" | ||
expect(player.scissors).to eq "You lose! :(" | ||
end | ||
|
||
it "correctly identifies draw" do | ||
player = Player.new | ||
$pc_plays = "scissors" | ||
expect(player.scissors).to eq "It's a tie!" | ||
end | ||
end | ||
|
||
context "when player chooses paper" do | ||
it "correctly identifies win" do | ||
player = Player.new | ||
$pc_plays = "rock" | ||
expect(player.paper).to eq "You win!" | ||
end | ||
|
||
it "correctly identifies lost" do | ||
player = Player.new | ||
$pc_plays = "scissors" | ||
expect(player.paper).to eq "You lose!" | ||
end | ||
|
||
it "correctly identifies draw" do | ||
player = Player.new | ||
$pc_plays = "paper" | ||
expect(player.paper).to eq "It's a tie!" | ||
end | ||
end | ||
end | ||
|
||
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. Very tidy and easy to follow |
||
|
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,9 @@ | ||
<!-- in views/index.erb --> | ||
<h1>ROCK PAPER SCISSORS!</h1> | ||
<h2>Who wishes to challenge me?</h2> | ||
<form action="/submit-name" method="post"> | ||
<label for="player_name"> | ||
<input type="text" name="player_name"> | ||
</label> | ||
<input type="submit" value="Submit"> | ||
</form> |
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,15 @@ | ||
<!-- in views/results.erb --> | ||
<h1>ROCK PAPER SCISSORS!</h1> | ||
<h2> <%=session["player_name"]%>, let's play! Choose your weapon:</h2> | ||
|
||
<form action="/rock" method="get"> | ||
<input type="submit" value="ROCK"> | ||
</form> | ||
|
||
<form action="/paper" method="get"> | ||
<input type="submit" value="PAPER"> | ||
</form> | ||
|
||
<form action="/scissors" method="get"> | ||
<input type="submit" value="SCISSORS"> | ||
</form> |
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,4 @@ | ||
<!-- in views/rock.erb --> | ||
<h1>Your <%=$player_plays%> takes on the computer's <%=$pc_plays%>...</h1> | ||
|
||
<h2>Result: <%=$result%></h2> |
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 forgot the brackets lol thanks