class PlayGOT::Player
Attributes
allies[RW]
chosen[RW]
defeated[RW]
enemies[RW]
house[RW]
loyalty[RW]
name[RW]
secret_weapons[RW]
stamina[RW]
tactic[RW]
Public Class Methods
new()
click to toggle source
# File lib/play_GOT/player.rb, line 4 def initialize @name = gets.strip end
Public Instance Methods
choose_house()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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