Class: SakuRps::Arena
- Inherits:
-
Object
- Object
- SakuRps::Arena
- Defined in:
- lib/saku_rps/arena.rb
Instance Attribute Summary collapse
-
#player_1 ⇒ Object
Returns the value of attribute player_1.
-
#player_2 ⇒ Object
Returns the value of attribute player_2.
-
#rps_game ⇒ Object
Returns the value of attribute rps_game.
-
#rps_game_wins ⇒ Object
Returns the value of attribute rps_game_wins.
Instance Method Summary collapse
- #check_game ⇒ Object
- #clash ⇒ Object
- #display_score(wins) ⇒ Object
- #end_game(winner) ⇒ Object
-
#initialize(rps_game) ⇒ Arena
constructor
A new instance of Arena.
- #intro ⇒ Object
- #play ⇒ Object
- #run ⇒ Object
- #turn_acc(last_turn_winner) ⇒ Object
Constructor Details
#initialize(rps_game) ⇒ Arena
Returns a new instance of Arena.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/saku_rps/arena.rb', line 6 def initialize(rps_game) @rps_game = rps_game @rps_game_wins = rps_game.game_state[:wins] @player_1 = rps_game.players[:player_1] @player_2 = rps_game.players[:player_2] @rps_game_wins = { @player_1.name => 0, @player_2.name => 0 } end |
Instance Attribute Details
#player_1 ⇒ Object
Returns the value of attribute player_1.
4 5 6 |
# File 'lib/saku_rps/arena.rb', line 4 def player_1 @player_1 end |
#player_2 ⇒ Object
Returns the value of attribute player_2.
4 5 6 |
# File 'lib/saku_rps/arena.rb', line 4 def player_2 @player_2 end |
#rps_game ⇒ Object
Returns the value of attribute rps_game.
4 5 6 |
# File 'lib/saku_rps/arena.rb', line 4 def rps_game @rps_game end |
#rps_game_wins ⇒ Object
Returns the value of attribute rps_game_wins.
4 5 6 |
# File 'lib/saku_rps/arena.rb', line 4 def rps_game_wins @rps_game_wins end |
Instance Method Details
#check_game ⇒ Object
88 89 90 91 92 |
# File 'lib/saku_rps/arena.rb', line 88 def check_game end_game(player_1.name) if rps_game_wins[player_1.name] == 2 end_game(player_2.name) if rps_game_wins[player_2.name] == 2 display_score(rps_game_wins) if rps_game.game_state[:won] == false end |
#clash ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/saku_rps/arena.rb', line 53 def clash puts "\n" puts "#{player_1.name} picked #{player_1.choice}!!!" puts "#{player_2.name} picked #{player_2.choice}!!!" if player_1.choice == player_2.choice puts "The might of #{player_1.choice} is an equal match for #{player_2.choice}\n" turn_acc('DRAW') else if player_2.choice == rps_game.win_tree[player_1.choice] puts "#{player_2.name}'s #{player_2.choice} defeats #{player_1.name}'s #{player_1.choice}\n" turn_acc(player_2.name) elsif player_1.choice == rps_game.win_tree[player_2.choice] puts "#{player_1.name}'s #{player_1.choice} defeats #{player_2.name}'s #{player_2.choice}\n" turn_acc(player_1.name) end end end |
#display_score(wins) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/saku_rps/arena.rb', line 103 def display_score(wins) wins.each do |player, score| puts "#{player}: #{score}" end puts "\n" end |
#end_game(winner) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/saku_rps/arena.rb', line 94 def end_game(winner) rps_game.game_state[:winner] = winner rps_game.game_state[:won] = true puts "*****\n" puts "And the winner is....#{rps_game.game_state[:winner]}!!!!" puts 'With a final score of: ' display_score(rps_game_wins) end |
#intro ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/saku_rps/arena.rb', line 18 def intro print `clear` puts 'Welcome to the high ocatane world of RPS!' puts "Let's get ready to RUUUUUUUMBLE!!" sleep(1) 3.times do |i| puts "#{i + 1}!" sleep(0.5) end puts 'Go!!!' print `clear` play end |
#play ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/saku_rps/arena.rb', line 33 def play begin run rescue SystemExit, Interrupt end puts "\nGoodbye!" end |
#run ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/saku_rps/arena.rb', line 42 def run check_game if rps_game.game_state[:won] == true puts 'Thanks for playing!' elsif rps_game.game_state[:won] == false # make this into a choice method for the player rps_game.players.each_value(&:choose_play) clash end end |
#turn_acc(last_turn_winner) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/saku_rps/arena.rb', line 75 def turn_acc(last_turn_winner) case last_turn_winner when player_1.name rps_game_wins[player_1.name] += 1 run when player_2.name rps_game_wins[player_2.name] += 1 run else run end end |