Class: GameSelect
- Inherits:
-
Object
- Object
- GameSelect
- Defined in:
- lib/destiny.rb
Instance Attribute Summary collapse
-
#game_select ⇒ Object
Returns the value of attribute game_select.
Instance Method Summary collapse
-
#initialize(default = "default") ⇒ GameSelect
constructor
A new instance of GameSelect.
- #outcome ⇒ Object
Constructor Details
#initialize(default = "default") ⇒ GameSelect
Returns a new instance of GameSelect.
27 28 29 30 31 32 |
# File 'lib/destiny.rb', line 27 def initialize default="default" #rspec with user input is more tricky, this allows me to test @default = default return @game_select = @default if @default != "default" yes_no end |
Instance Attribute Details
#game_select ⇒ Object
Returns the value of attribute game_select.
25 26 27 |
# File 'lib/destiny.rb', line 25 def game_select @game_select end |
Instance Method Details
#outcome ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/destiny.rb', line 34 def outcome if @game_select == "yes" # this is purely for rspec # return "Starting a new game, please answer the following questions:" if @default != "default" begin puts # formatting puts "_"*50 puts "Starting a new game, please answer the following questions:" puts "Whould you like to play as a knight or wizard?" puts "[1]. Knight" puts "[2]. Wizard" prompt; class_choice = gets.chomp end while not (class_choice == "1" or class_choice == "2") begin player_name = choose_name puts #formatting puts "You have chosen #{player_name} as your character's name. Is this correct?" puts "Please enter [yes] to confirm." prompt; confirm_name = STDIN.gets.chomp.downcase end while not (confirm_name == "yes") if class_choice == "1" @player = Knight.new elsif class_choice == "2" @player = Wizard.new end # Set player name, write attributes to save file, then return player to binary @player.name = "#{player_name}" save_data # Intro for new players puts #formatting puts "Prepare ye, #{@player.name} for great adventure!" puts "Ye are a young #{@player.class} with magnificent deeds ahead of ye!" puts # formatting @player elsif @game_select == "no" # for rspec return "Loading the existing game." if @default != "default" puts # formatting puts "Loading the existing game." puts # formatting @player = load_data end end |