Class: PlayGOT::Player
- Inherits:
-
Object
- Object
- PlayGOT::Player
- Defined in:
- lib/play_GOT/player.rb
Instance Attribute Summary collapse
-
#allies ⇒ Object
Returns the value of attribute allies.
-
#chosen ⇒ Object
Returns the value of attribute chosen.
-
#defeated ⇒ Object
Returns the value of attribute defeated.
-
#enemies ⇒ Object
Returns the value of attribute enemies.
-
#house ⇒ Object
Returns the value of attribute house.
-
#loyalty ⇒ Object
Returns the value of attribute loyalty.
-
#name ⇒ Object
Returns the value of attribute name.
-
#secret_weapons ⇒ Object
Returns the value of attribute secret_weapons.
-
#stamina ⇒ Object
Returns the value of attribute stamina.
-
#tactic ⇒ Object
Returns the value of attribute tactic.
Instance Method Summary collapse
- #choose_house ⇒ Object
- #continue ⇒ Object
- #fight ⇒ Object
- #fight_or_flee ⇒ Object
- #flee ⇒ Object
-
#initialize ⇒ Player
constructor
A new instance of Player.
- #make_ally ⇒ Object
- #select_enemy ⇒ Object
- #status ⇒ Object
- #survive_winter ⇒ Object
Constructor Details
#initialize ⇒ Player
Returns a new instance of Player.
4 5 6 |
# File 'lib/play_GOT/player.rb', line 4 def initialize @name = gets.strip end |
Instance Attribute Details
#allies ⇒ Object
Returns the value of attribute allies.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def allies @allies end |
#chosen ⇒ Object
Returns the value of attribute chosen.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def chosen @chosen end |
#defeated ⇒ Object
Returns the value of attribute defeated.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def defeated @defeated end |
#enemies ⇒ Object
Returns the value of attribute enemies.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def enemies @enemies end |
#house ⇒ Object
Returns the value of attribute house.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def house @house end |
#loyalty ⇒ Object
Returns the value of attribute loyalty.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def loyalty @loyalty end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def name @name end |
#secret_weapons ⇒ Object
Returns the value of attribute secret_weapons.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def secret_weapons @secret_weapons end |
#stamina ⇒ Object
Returns the value of attribute stamina.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def stamina @stamina end |
#tactic ⇒ Object
Returns the value of attribute tactic.
2 3 4 |
# File 'lib/play_GOT/player.rb', line 2 def tactic @tactic end |
Instance Method Details
#choose_house ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/play_GOT/player.rb', line 9 def choose_house puts "Choose a number from the list of great houses and swear your allegience: ".light_red PlayGOT::House.list_all input = gets.strip.to_i if (1..PlayGOT::House.all.size).to_a.include?(input) @house = PlayGOT::House.find(input) @secret_weapons = @house.ancestral_weapons @stamina = 50 @tactic = 50 @loyalty = 50 @allies = [] @defeated = [] @enemies = PlayGOT::House.all - [@house] case @house.name when "House Hightower of the Hightower" @tactic += 10 when "House Lannister of Casterly Rock" @stamina -= 5 @tactic += 15 when "House Mormont of Bear Island" @stamina += 5 @tactic -= 5 @loyalty += 10 when "House Royce of Runestone" @stamina += 5 @tactic += 5 when "House Stark of Winterfell" @tactic -= 5 @loyalty += 15 when "House Targaryen of King's Landing" @stamina += 15 @loyalty -= 5 when "House Tarly of Horn Hill" @tactic += 5 @loyalty += 5 end else puts "You've spoken something mystical that I don't understand.".light_red choose_house end end |
#continue ⇒ Object
199 200 201 202 203 |
# File 'lib/play_GOT/player.rb', line 199 def continue puts "\nWhen you are ready, press any key to continue.".light_red input = gets.strip end |
#fight ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/play_GOT/player.rb', line 139 def fight puts "You are going into battle with #{@chosen.name.light_green}. Rally your soldiers!" game = PlayGOT::RockPaperScissors.new if game.your_score == 3 puts "Congratulations! You've defeated #{@chosen.name.light_green}. Your men are singing your name. You are one step closer to the Throne!" @defeated << @chosen @enemies.delete(@chosen) else @stamina -= 5 puts "You lost in the battle with #{@chosen.name.light_green}. Your #{"stamina".light_green} now decreases to #{@stamina.to_s.light_green}%." end end |
#fight_or_flee ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/play_GOT/player.rb', line 121 def fight_or_flee puts "TOO LATE! #{@chosen.name.light_green} has prepared to attack. Are you ready to fight? Or you can try to flee." puts "1 - fight\n2 - flee".blue input = gets.strip case input when "1" fight when "2" flee else puts "You've spoken something mystical that I don't understand.".light_red fight_or_flee end end |
#flee ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/play_GOT/player.rb', line 155 def flee puts "Your #{'tactic'.light_green} determines your probability of fleeing from an enemy. Your current chance of success is #{@tactic.to_s.light_green}%. Ready to roll the dice?" continue roll_dice = rand(100) if roll_dice < @tactic puts "THAT WAS CLOSE! You've dodged a spear. Now lay low and make your way back to the camp." else puts "AMBUSH! You are cornered. Your enemies are close.\nFight is your only way out. Fight in the name of your House!" continue fight end end |
#make_ally ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/play_GOT/player.rb', line 99 def make_ally puts "You are about to approach the #{@chosen.name.light_green}. Your #{'loyalty'.light_green} determines your probability of winning over an ally. Your current chance of success is #{@loyalty.to_s.light_green}%. Ready to roll the dice?" continue roll_dice = rand(100) if roll_dice < @loyalty puts "LUCK IS ON YOUR SIDE, #{@name.light_green}. You've made a new ally, #{@chosen.name.light_green}." @stamina += 5 @allies << @chosen @enemies.delete(@chosen) @secret_weapons << @chosen.ancestral_weapons puts "Your #{'stamina'.light_green} now increases to #{@stamina.to_s.light_green}%. You've gained weapon #{@chosen.ancestral_weapons.join(" and ").light_green}. You have one less enemy." else fight_or_flee end end |
#select_enemy ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/play_GOT/player.rb', line 81 def select_enemy puts "Who's on your mind?".light_red @enemies.each.with_index(1) do |e, i| puts "#{i} - #{e.name}".blue end input = gets.strip.to_i if (1..@enemies.size).to_a.include?(input) @chosen = @enemies[input - 1] else puts "You've spoken something mystical that I don't understand.".light_red select_enemy end end |
#status ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/play_GOT/player.rb', line 55 def status puts "Your name is #{@name.light_green}, Lord of the #{@house.name.light_green}." puts "You possess #{@secret_weapons.join(", ").light_green}, ancestral weapon from your House and your allies." puts "Your stats are: [stamina: #{@stamina.to_s.light_green}, tactic: #{@tactic.to_s.light_green}, loyalty: #{@loyalty.to_s.light_green}]." if @allies.size > 0 allies = @allies.collect {|a| a.name} puts "\nYour current allies are: #{allies.join(", ").light_green}." else puts "\nYou currently have no allies. Go and make one.".blue end if @defeated.size > 0 defeated = @defeated.collect {|d| d.name} puts "\nYou have defeated: #{defeated.join(", ").light_green}." end if @enemies.size > 0 enemies = @enemies.collect {|e| e.name} puts "\nYour current enemies are: #{enemies.join(", ").light_green}. Conquer all of them or turn them into your allies." else puts "\nYou've destroyed all your enemies. The Throne is yours!".blue end end |
#survive_winter ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/play_GOT/player.rb', line 174 def survive_winter puts "Winter is coming. He brings the storm. When the snows fall and the white winds blow, Nothing burns like the cold.\n" puts "\nEvery man must die. But first he must live.\n".blue puts "Your #{'stamina'.light_green} determines your probability of surviving the Winter. Your current chance of success is #{@stamina.to_s.light_green}%. Can you survive the night?" continue roll_dice = rand(100) if roll_dice < @stamina puts "YOU'VE MADE IT. He retreated. Now stay safe. CONSTANT VIGILANCE!\n".blue else puts "He is too powerful. You cannot withstand.\n" puts "\nYour men brought you back to #{@house.region.gsub("The", "the").light_green}. You people say, 'Brave as #{@name.light_green}, Lord of the #{@house.name.light_green}. He's the only one who has fought the Night.'" puts "\nNever forget what you are, for surely the world will not. See you next time in the Game of Thrones.\n".blue exit! end end |