class Game

Constants

ITEM_LIST
MON_LIST
PLAYER_ATTR
ROOM_ATTR

Declare constants for attribute storage

Public Class Methods

final() click to toggle source

Final text sequence and end of game

# File lib/main.rb, line 149
def self.final
    box = TTY::Box.frame(width: 100, height: 15, align: :center, padding: 3, border: :thick,
        title: {top_left: "|Dungeons of Heck|", bottom_right: "|Final|"}) do
            "You, #{PLAYER_ATTR[:player_name].upcase.yellow}, flee the flaming #{'CRYPT'.green} as smoke billows out from the entrance and between the ancient brickwork. With suprising speed, you seen the #{"HECK WIZARD".red} is giving chase and boy is he mad! \nLike the wind, out the #{'GATE'.green} you shoot and down the road. \nThe #{"HECK WIZARD".red} chases you for a little bit but turns around when he hears the fire engine coming down the road from the other direction. \nOne day you may return but for now you think you better lay low and content yourself with having rid the land of one more #{'NOISY HOOVER'.red}."
        end
    system('clear') || system('cls')
    puts box
    prompt.keypress("Press space or enter to fulfill your destiny!".green, keys: [:space, :return])
    exit
end

Public Instance Methods

game_menu() click to toggle source

Method for game menu loop

# File lib/main.rb, line 163
def game_menu
    system('clear') || system('cls')
    box = TTY::Box.frame(width: 100, height: 13, align: :center, padding: [3,0], border: :thick,
        title: {top_left: "|Dungeons of Heck|", bottom_right: "|Location: #{ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:location_name]}|"}) do
            if ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:visited?]
                ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:look_text]
            else
                ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:intro_text]
            end
        end
    puts box
    ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:visited?] = true

    prompt.select("Choose your FATE".red) do |menu|
        if ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:monster?] && !ROOM_ATTR[PLAYER_ATTR[:player_location_id]][:monster_defeat?]
        menu.choice "Fight!", -> {Battle::fight; game_menu}
        end
        menu.choice "Move", -> {Action::move; game_menu}
        menu.choice "Use", -> {Action::use; game_menu}
        menu.choice "Inventory", -> {Action::bag; game_menu}
        menu.choice "Quit", -> {Action::exit_game}
    end
end
introduction() click to toggle source

Method for getting the player name and introducting the player to the game before starting the game_menu loop

# File lib/main.rb, line 190
def introduction
    puts "\nHumble doge, what is your true name?".light_blue
    begin
        PLAYER_ATTR[:player_name] = gets.chomp.strip.upcase
    raise NotValidName if PLAYER_ATTR[:player_name].match?(/[^a-zA-Z]/) || PLAYER_ATTR[:player_name].length > 7 || PLAYER_ATTR[:player_name].length < 1 # Name must be letters and less than 8 characters
    rescue NotValidName => e
        puts e.message
        retry
    end

    puts "\nHumble doge, what is your true age?".light_blue
    begin
        PLAYER_ATTR[:player_age] = Integer(gets) rescue 0
    raise NotValidAge unless PLAYER_ATTR[:player_age] > 0
    rescue NotValidAge => e
        puts e.message
        retry
    end
    
    if PLAYER_ATTR[:player_age] > 15
        puts "\nWow, that's heckin' old for a doge but if you say so.".light_blue
    else
        puts "\n#{PLAYER_ATTR[:player_age]} is a fine age for a doge adventurer such as yourself.".light_blue
    end

    puts "\nMighty ".light_blue + "#{PLAYER_ATTR[:player_name].upcase.yellow}" + ", this is your tale.".light_blue

    box = TTY::Box.frame(width: 100, height: 15, align: :center, padding: 3, border: :thick,
        title: {top_left: "|Dungeons of Heck|", bottom_right: "|Introduction|"}) do
            "The cold wind blows harshly against your snoot. You lick it to keep it moist and glistening as you take in your surroundings. \nYou are #{PLAYER_ATTR[:player_name].upcase.yellow} and you are a #{'GOOD BOY'.green}. \nYou have travelled following rumours and tales of a heckin' evil place where #{'BAD DOGES'.red} and \n#{'NOISY APPLIANCES'.red} are said to lurk. You have tasked yourself with destroying heckin' bad things across the land and now you have arrived outside the grounds of an imposing castle said to be built upon the most heckin' place of all, the #{'DUNGEONS OF HECK'.red}."
        end

    prompt.keypress("Press space or enter to continue".green, keys: [:space, :return])
    system('clear') || system('cls')
    puts box

    prompt.keypress("Press space or enter to continue".green, keys: [:space, :return])
    PLAYER_ATTR[:player_location_id] = 0
    game_menu
end
main_menu() click to toggle source

Method for the main menu when starting the game