lib/GameApp.rb
# Allows player to delete heroes and their associated journeys
Allows player to delete heroes and their associated journeys
Allows player to delete heroes and their associated journeys
def delete_game
    if Hero.count > 0
      display_heroes = Hero.all.map {|h| "#{h.id}. #{h.name} with Experience: #{h.experience} and Health: #{h.current_health}."}
      delete_choice = @@prompt.select("Select the hero you want to delete.", display_heroes)
      delete_hero = Hero.find(delete_choice.split[0])
      system("clear")
      display_title
      delete_confirmation = @@prompt.select("Are you sure you want to delete #{delete_hero.name}?", "Yes, delete #{delete_hero.name}", "No, go back to Main Menu.")
      case delete_confirmation
      when "Yes, delete #{delete_hero.name}"
        Journey.where(:hero_id => delete_hero.id)
          .map {|journey| journey.id}
          .map {|id| Journey.destroy(id)}
        Hero.destroy(delete_hero.id)
        puts "\n\n"
        puts "#{delete_hero.name} deleted. Going back to Main Menu."
        sleep(3)
        main_menu
      when "No, go back to Main Menu."
        main_menu
      end
    else
      display_no_heroes
      main_menu
    end
  end
def delete_game if Hero . count > 0 display_heroes = Hero . all . map { | h | "#{h.id}. #{h.name} with Experience: #{h.experience} and Health: #{h.current_health}." } delete_choice = @@prompt . select ( "Select the hero you want to delete." , display_heroes ) delete_hero = Hero . find ( delete_choice . split [ 0 ] ) system ( "clear" ) display_title delete_confirmation = @@prompt . select ( "Are you sure you want to delete #{delete_hero.name}?" , "Yes, delete #{delete_hero.name}" , "No, go back to Main Menu." ) case delete_confirmation when "Yes, delete #{delete_hero.name}" Journey . where ( :hero_id => delete_hero . id ) . map { | journey | journey . id } . map { | id | Journey . destroy ( id ) } Hero . destroy ( delete_hero . id ) puts "\n\n" puts "#{delete_hero.name} deleted. Going back to Main Menu." sleep ( 3 ) main_menu when "No, go back to Main Menu." main_menu end else display_no_heroes main_menu end end
Allows player to delete heroes and their associated journeys
Allows player to delete heroes and their associated journeys