class Game

Public Class Methods

new(maze) click to toggle source
# File lib/game/game.rb, line 4
def initialize(maze)
        @maze = maze
end

Public Instance Methods

generate_goal(dificulty) click to toggle source
# File lib/game/game.rb, line 31
def generate_goal(dificulty)
        selected_cell = select_goal_cell dificulty
        indices = @maze.coords_to_indices *selected_cell.coords
params = indices.clone
params.push 2
        @maze.set_raw_value *params
        @maze
end
select_goal_cell(dificulty) click to toggle source
# File lib/game/game.rb, line 8
def select_goal_cell(dificulty)
        dificulty = dificulty.to_sym
        solver = TreeSolver.new @maze
        start_coords = [0]*@maze.dimensions.length
        paths = solver.paths *start_coords
        leafs = {}
        paths.each_leaf do |leaf|
                leafs[leaf.node_depth] = leaf
        end
        depths = leafs.keys.sort
        case dificulty
        when :easy
                selected_depth = depths[(depths.size/4).ceil]
        when :medium
                selected_depth = depths[(depths.size/2).ceil]
        when :hard
                selected_depth = depths.last
        else
                selected_depth = depths[(depths.size/2.0).floor + rand((depths.size/2.0).round)]
        end
        leafs[selected_depth].content
end