Class: GameSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/destiny.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default = "default") ⇒ GameSelect

Returns a new instance of GameSelect.



28
29
30
31
32
33
# File 'lib/destiny.rb', line 28

def initialize default="default"
  #rspec with user input is more tricky, this allows me to test no response
  @default = default
  return @yes_no = @default if @default != "default"
  yes_no
end

Instance Attribute Details

#game_selectObject

Returns the value of attribute game_select.



26
27
28
# File 'lib/destiny.rb', line 26

def game_select
  @game_select
end

Instance Method Details

#outcomeObject



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
77
78
79
80
81
82
83
# File 'lib/destiny.rb', line 35

def outcome
  if @yes_no == "yes"
    begin
      puts # formatting
      puts "_"*50
      puts "Starting a new game, please answer the following questions:"
      c = Choice.new "Whould you like to play as a knight, wizard, cleric, or rogue?",
        {
          "1" => "Knight",
          "2" => "Wizard",
          "3" => "Cleric",
          "4" => "Rogue"
        }
        class_choice = c.prompt
    end while not (class_choice == "1" or class_choice == "2" or class_choice == "3" or class_choice == "4")
    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
    elsif class_choice == "3"
      @player = Cleric.new
    elsif class_choice == "4"
      @player = Rogue.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 @yes_no == "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