-
Notifications
You must be signed in to change notification settings - Fork 1.9k
rps challenge #1036
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
Open
m-rcd
wants to merge
35
commits into
makersacademy:main
Choose a base branch
from
m-rcd:master
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
rps challenge #1036
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
98ba70a
player can add name
m-rcd 28342c3
add options
m-rcd c162337
add rps game class
m-rcd 1c3ecf5
add player class
m-rcd a813fb4
add computer class
m-rcd 1a19870
add result page with game result
m-rcd 8a613a9
add web helpers
m-rcd 28ae181
fix play method
m-rcd 0030db3
add player2
m-rcd 777d893
can play solo or multiplayer
m-rcd 4f919da
can start new game when game ends
m-rcd 0814d39
refactor tests
m-rcd dd799ed
refactor
m-rcd 45cc6c3
add css
m-rcd 8831ed0
fix css
m-rcd 548501d
prevent empty fields
m-rcd 53495db
change pic
m-rcd 76f8942
add README
m-rcd 9bbf44e
ready for deployment
m-rcd 825f8ca
add link to README
m-rcd abfdf87
capitalize player name
m-rcd 5944dd1
fix name capitalize
m-rcd ee7f159
add computer choice when game ends
m-rcd 91b2898
refactor
m-rcd 408a829
fix 1 player display bug
m-rcd 0576887
fix message when computer wins
m-rcd a4b50c1
fix test
m-rcd 96d350c
remove unnecessary code
m-rcd fc33469
remove computer class and refactor controller to one path
m-rcd e85290f
refactor based on reviews
m-rcd dfd35ec
fix bug
m-rcd b9cf451
remove index.php
m-rcd c998c3c
Update readme
m-rcd 0e4b2f0
Fix titles in README
m-rcd 1d53bed
Refacto
m-rcd 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ source 'https://rubygems.org' | |
ruby '2.5.0' | ||
|
||
gem 'rake' | ||
gem 'shotgun' | ||
gem 'sinatra' | ||
|
||
group :test do | ||
|
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,68 @@ | ||
require 'sinatra/base' | ||
require './lib/game' | ||
require './lib/player' | ||
|
||
class RPS < Sinatra::Base | ||
enable :sessions | ||
|
||
get '/' do | ||
erb :index | ||
end | ||
|
||
post '/game_mode' do | ||
session[:game_mode] = params[:game_mode].to_sym | ||
@gamemode = session[:game_mode] | ||
erb :name_input | ||
end | ||
|
||
post '/name' do | ||
player1 = Player.new(params[:player1]) | ||
if @gamemode == :singleplayer | ||
player2 = Player.new('Skynet') | ||
else | ||
player2 = Player.new(params[:player2]) | ||
end | ||
session[:game] = Game.new(player1, player2) | ||
redirect '/play' | ||
end | ||
|
||
get '/play' do | ||
@game = session[:game] | ||
erb :optionp1 | ||
end | ||
|
||
post '/optionp1' do | ||
@gamemode = session[:game_mode] | ||
session[:player1_choice] = params[:commit] | ||
if @gamemode == :singleplayer | ||
redirect '/result' | ||
else | ||
redirect '/playp2' | ||
end | ||
end | ||
|
||
get '/playp2' do | ||
@game = session[:game] | ||
erb :optionp2 | ||
end | ||
|
||
post '/optionp2' do | ||
session[:player2_choice] = params[:option] | ||
redirect '/result' | ||
end | ||
|
||
get '/result' do | ||
@game = session[:game] | ||
@gamemode = session[:game_mode] | ||
@game.player1.choice(session[:player1_choice]) | ||
if @gamemode == :singleplayer | ||
@game.player2.choice(@game.computer_choice) | ||
else | ||
@game.player2.choice(session[:player2_choice]) | ||
end | ||
@result = @game.play | ||
erb :result | ||
end | ||
|
||
run! if app_file == $0 | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
class Game | ||
attr_reader :player1, :result, :player2 | ||
|
||
def initialize(player1, player2) | ||
@player1 = player1 | ||
@player2 = player2 | ||
@key_beats_value = { :Rock => [:Scissors, :Lizard], :Paper => | ||
[:Rock, :Spock], :Scissors => [:Paper, :Lizard], | ||
:Spock => [:Scissors, :Rock], :Lizard => [:Spock, :Paper] } | ||
end | ||
|
||
def play | ||
p1 = player1.player_choice.to_sym | ||
p2 = player2.player_choice.to_sym | ||
if @key_beats_value[p1].include?(p2) | ||
'player1' | ||
elsif @key_beats_value[p2].include?(p1) | ||
'player2' | ||
else | ||
'draw' | ||
end | ||
end | ||
|
||
def computer_choice | ||
['Rock', 'Paper', 'Scissors', 'Spock', 'Lizard'].sample | ||
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,11 @@ | ||
class Player | ||
attr_reader :name, :player_choice | ||
|
||
def initialize(name) | ||
@name = name | ||
end | ||
|
||
def choice(choice) | ||
@player_choice = choice | ||
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,75 @@ | ||
.button { | ||
display: inline-block; | ||
width: 120px; | ||
background-color: #8A2BE2 ; | ||
border: 2px solid white; | ||
color: white; | ||
text-decoration: none; | ||
text-align: center; | ||
border-radius: 4px; | ||
margin-left: 5px; | ||
margin-right: 5px; | ||
margin-bottom: 20px; | ||
padding-bottom: 2px; | ||
padding-top: 2px; | ||
font-size: 16px; | ||
font-family: Times, Georgia, Serif; | ||
cursor: pointer; | ||
} | ||
|
||
body { | ||
margin-top: 100px; | ||
background-color: black; | ||
color: white; | ||
font-family: "Courier New", Courier, monospace; | ||
font-size: 20px; | ||
} | ||
|
||
|
||
body a { | ||
color: white; | ||
text-decoration: none; | ||
font-family: "Courier New", Courier, monospace; | ||
font-size: 65px; | ||
text-align: center; | ||
margin: 60px; | ||
display: block; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
font-size: 60px; | ||
|
||
} | ||
|
||
.im { | ||
position: relative; | ||
top: -140px; | ||
right: -100px; | ||
} | ||
|
||
|
||
form { | ||
text-align: center; | ||
} | ||
|
||
p { | ||
text-align: center; | ||
font-size: 70px; | ||
} | ||
h2 { | ||
text-align: center; | ||
font-size: 50px; | ||
} | ||
|
||
form input[type='text'] { | ||
border: 2px solid #8A2BE2 ; | ||
font-family: "Courier New", Courier, monospace; | ||
font-size: 16px; | ||
text-align: center; | ||
width: 200px; | ||
padding: 3px; | ||
margin-top: 40px; | ||
background-color: white; | ||
|
||
} |
Oops, something went wrong.
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.
Great that you got this hosted!