-
Notifications
You must be signed in to change notification settings - Fork 30
Added faker gem to Gemfile #18
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
cmwchoi
wants to merge
2
commits into
paircolumbus:master
Choose a base branch
from
cmwchoi:christianchoi
base: master
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
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
Binary file not shown.
This file contains hidden or 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 @@ | ||
| # A sample Gemfile | ||
| source "https://rubygems.org" | ||
|
|
||
| # gem "rails" | ||
| gem 'faker' |
This file contains hidden or 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 @@ | ||
| GEM | ||
| remote: https://rubygems.org/ | ||
| specs: | ||
| faker (1.6.1) | ||
| i18n (~> 0.5) | ||
| i18n (0.7.0) | ||
|
|
||
| PLATFORMS | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| faker | ||
|
|
||
| BUNDLED WITH | ||
| 1.11.2 |
This file contains hidden or 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,121 @@ | ||
| require_relative 'view' | ||
| require_relative 'model' | ||
|
|
||
| class RPSController | ||
| include RPSView | ||
|
|
||
| attr_reader :choices | ||
|
|
||
| def initialize | ||
| @choices = {"rock" => 1, "paper" => 2, "scissors" => 3} | ||
| end | ||
|
|
||
| def run! | ||
| # choices = Choices.new | ||
| player = Player.new | ||
| Print::title | ||
|
|
||
| loop do | ||
| Print::menu | ||
| case get_input.to_i | ||
| when 1 | ||
| num_rounds = 0 | ||
| loop do | ||
| num_rounds = get_input(Print::request_rounds).to_i | ||
| if num_rounds > 0 and num_rounds < 6 | ||
| break | ||
| else | ||
| Print::error_message | ||
| end | ||
| end | ||
| num_rounds.times { |x| play(x + 1, player) } | ||
| print_player_results(player) | ||
| update_score(player) | ||
| player.reset | ||
| when 2 | ||
| puts "Records" | ||
| print_player_records(player) | ||
| when 3 | ||
| puts "Thanks for playing. Goodbye!" | ||
| exit | ||
| else | ||
| Print::error_message | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
| def play(number, player) | ||
| comp_value = rand(1..3) | ||
| comp_choice = choices.key(comp_value) | ||
| loop do | ||
| print "Round #{number}! " | ||
| case get_input(Print::request_rps) | ||
| when "rock" | ||
| Print::run_spinner | ||
| puts "PLAYER: rock\t\tCOMPUTER: #{comp_choice}" | ||
| determine_outcome("rock", comp_value, player) #DRY. need to refactor | ||
| break | ||
| when "paper" | ||
| Print::run_spinner | ||
| puts "PLAYER: paper\t\tCOMPUTER: #{comp_choice}" | ||
| determine_outcome("paper", comp_value, player) | ||
| break | ||
| when "scissors" | ||
| Print::run_spinner | ||
| puts "PLAYER: scissors\tCOMPUTER: #{comp_choice}" | ||
| determine_outcome("scissors", comp_value, player) | ||
| break | ||
| else | ||
| Print::error_message | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def print_player_records(player) | ||
| puts "Games won: #{player.game_wins}" | ||
| puts "Games lost: #{player.game_losses}" | ||
| puts "Games tied: #{player.game_ties}" | ||
| end | ||
|
|
||
| def update_score(player) | ||
| if player.round_wins > player.round_losses | ||
| player.win_game | ||
| elsif player.round_wins < player.round_losses | ||
| player.lose_game | ||
| else | ||
| player.tie | ||
| end | ||
| end | ||
|
|
||
| def print_player_results(player) | ||
| puts "Wins: #{player.round_wins} Losses: #{player.round_losses}" | ||
| end | ||
|
|
||
| def get_input(question=nil) | ||
| puts question if question | ||
| print "> " | ||
| gets.chomp.downcase | ||
| end | ||
|
|
||
| def play_again? | ||
| ['y', 'yes'].include? get_input | ||
| end | ||
|
|
||
| def determine_outcome(player_choice, computer_value, player) | ||
| player_value = choices[player_choice] | ||
| difference = player_value - computer_value | ||
| if difference == 0 | ||
| Print::player_ties | ||
| elsif difference == 1 or difference == -2 | ||
| Print::player_wins | ||
| player.win_round | ||
| else | ||
| Print::player_loses | ||
| player.lose_round | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
| RPSController.new.run! | ||
This file contains hidden or 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,51 @@ | ||
| class Player | ||
| attr_reader :round_wins, :round_losses, :game_wins, :game_losses, :game_ties | ||
|
|
||
| def initialize | ||
| @round_wins = 0 | ||
| @round_losses = 0 | ||
| @game_wins = 0 | ||
| @game_losses = 0 | ||
| @game_ties = 0 | ||
| end | ||
|
|
||
| def win_round | ||
| @round_wins += 1 | ||
| end | ||
|
|
||
| def lose_round | ||
| @round_losses += 1 | ||
| end | ||
|
|
||
| def win_game | ||
| @game_wins += 1 | ||
| end | ||
|
|
||
| def lose_game | ||
| @game_losses += 1 | ||
| end | ||
|
|
||
| def tie | ||
| @game_ties += 1 | ||
| end | ||
|
|
||
| def reset | ||
| @round_wins = 0 | ||
| @round_losses = 0 | ||
| end | ||
|
|
||
| def update(player) | ||
| @game_wins = player.game_wins | ||
| @game_losses = player.game_losses | ||
| end | ||
|
|
||
| end | ||
|
|
||
| # class Choices | ||
| # attr_reader :hash | ||
|
|
||
| # def initialize | ||
| # @hash = {"rock" => 1, "paper" => 2, "scissors" => 3} | ||
| # end | ||
|
|
||
| # end |
This file contains hidden or 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 @@ | ||
| module RPSView | ||
|
|
||
| module Print | ||
|
|
||
| class << self | ||
| def title | ||
| title = <<TITLE | ||
|
|
||
| +=+=+=+=+=+=+=+=+=+=+=+ | ||
| | ROCK PAPER SCISSORS | | ||
| +=+=+=+=+=+=+=+=+=+=+=+ | ||
|
|
||
| TITLE | ||
|
|
||
| puts title | ||
| end | ||
|
|
||
| def menu | ||
| menu = <<MENU | ||
|
|
||
| *---Welcome---* | ||
| | (1) Play | | ||
| | (2) Records | | ||
| | (3) Quit | | ||
| *-------------* | ||
|
|
||
| MENU | ||
| puts menu | ||
| end | ||
|
|
||
| def request_rounds | ||
| puts "Enter how many rounds you'd like to play (1-5)?" | ||
| end | ||
|
|
||
| def request_rps | ||
| puts "Choose rock, paper, or scissors." | ||
| end | ||
|
|
||
| def run_spinner | ||
| print "Rock..."; sleep 0.5; | ||
| print "Paper..."; sleep 0.5; | ||
| print "Scissors..."; sleep 0.5; | ||
| puts "SHOOT!"; | ||
| end | ||
|
|
||
| def player_wins | ||
| puts "You WIN!" | ||
| end | ||
|
|
||
| def player_ties | ||
| puts "You TIED!" | ||
| end | ||
|
|
||
| def player_loses | ||
| puts "You LOSE" | ||
| end | ||
|
|
||
| def play_again? | ||
| puts "Play again? Y" | ||
| end | ||
|
|
||
| def error_message | ||
| puts "Invalid input. Please try again!" | ||
| end | ||
|
|
||
| end | ||
| end | ||
| end |
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 think generally we should prefer structured loops (
until ...,while ...), where the termination clause is explicitly defined at the beginning of the loop, rather thanloop dopatterns with a break tucked away somewhere in the body.