Class: SakuRps::RPS
- Inherits:
-
Object
- Object
- SakuRps::RPS
- Defined in:
- lib/saku_rps/rps.rb
Instance Attribute Summary collapse
-
#game_state ⇒ Object
readonly
Returns the value of attribute game_state.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#win_tree ⇒ Object
readonly
Returns the value of attribute win_tree.
-
#wins ⇒ Object
readonly
Returns the value of attribute wins.
Class Method Summary collapse
- .build_players(is_two_players) ⇒ Object
- .init ⇒ Object
- .num_of_players ⇒ Object
- .start(rps_game) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RPS
constructor
A new instance of RPS.
Constructor Details
#initialize(options = {}) ⇒ RPS
Returns a new instance of RPS.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/saku_rps/rps.rb', line 8 def initialize( = {}) @players = { } 2.times do |num| @players["player_#{num + 1}".to_sym] = [:players][num] end @game_state = { won: false, wins: {}, winner: '' } @win_tree = { 'SCISSORS' => 'ROCK', 'ROCK' => 'PAPER', 'PAPER' => 'SCISSORS' } end |
Instance Attribute Details
#game_state ⇒ Object (readonly)
Returns the value of attribute game_state.
6 7 8 |
# File 'lib/saku_rps/rps.rb', line 6 def game_state @game_state end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
6 7 8 |
# File 'lib/saku_rps/rps.rb', line 6 def players @players end |
#win_tree ⇒ Object (readonly)
Returns the value of attribute win_tree.
6 7 8 |
# File 'lib/saku_rps/rps.rb', line 6 def win_tree @win_tree end |
#wins ⇒ Object (readonly)
Returns the value of attribute wins.
6 7 8 |
# File 'lib/saku_rps/rps.rb', line 6 def wins @wins end |
Class Method Details
.build_players(is_two_players) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/saku_rps/rps.rb', line 56 def self.build_players(is_two_players) if is_two_players puts 'Please enter player 1\'s name!' print '> ' p1_name = gets.chomp puts 'Please enter player 2\'s name!' print '> ' p2_name = gets.chomp two_player = { players: [HumanPlayer.new(p1_name), HumanPlayer.new(p2_name)], } self.start(RPS.new(two_player)) else puts 'Please enter your name!' print '> ' p1_name = gets.chomp one_player = { players: [HumanPlayer.new(p1_name), CPUPlayer.new], } self.start(RPS.new(one_player)) end end |
.init ⇒ Object
27 28 29 30 31 |
# File 'lib/saku_rps/rps.rb', line 27 def self.init print `clear` puts "Welcome to the Rock! Paper! SCISSOOOOOOOOOOOOOORS!\n" num_of_players end |
.num_of_players ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/saku_rps/rps.rb', line 37 def self.num_of_players begin print `clear` puts 'Will this be a [One] or [Two] player game?' puts '1. One Player' puts '2. Two Players' print '> ' one_or_two_of_players = gets.chomp.to_s entry_check = %w(1 2).include?(one_or_two_of_players) puts "Please enter '1' for a single player game or '2' for a two player game" unless entry_check end until %w(1 2).include?(one_or_two_of_players) if one_or_two_of_players == '1' build_players(false) elsif one_or_two_of_players == '2' build_players(true) end end |
.start(rps_game) ⇒ Object
33 34 35 |
# File 'lib/saku_rps/rps.rb', line 33 def self.start(rps_game) Arena.new(rps_game).intro end |