Skip to content

Instantly share code, notes, and snippets.

@kirikak2
Created June 2, 2012 05:11
Show Gist options
  • Save kirikak2/2856695 to your computer and use it in GitHub Desktop.
Save kirikak2/2856695 to your computer and use it in GitHub Desktop.
minatork01 example1
require 'pry'
class AmidaLine
attr_reader :holizonal_lines
attr_reader :atari
def initialize(params = {})
@holizonal_lines = []
@atari = params[:atari]
end
end
class AmidaManager
def initialize(params = {})
@vertical = params[:vertial_line]
@holizonal = params[:holizonal_line]
@height = params[:height]
@vertical_lines = []
select_atari = rand(@vertical)
@vertical.times{|num|
atari = select_atari == num
@vertical_lines << AmidaLine.new(:atari => atari)
}
set_holizonal_line
print_amida
end
def set_holizonal_line
set_lines = 0
while set_lines < @holizonal
first_line = rand(@vertical)
height = rand(@height)
if line_writable?(first_line, height)
@vertical_lines[first_line].holizonal_lines[height] = true
set_lines = set_lines + 1
end
end
end
def print_amida
# create header
temp = []
alpha = %w{A B C D E F G H I J K L M N O P}
@vertical.times do |num|
temp << alpha[num]
temp << " "
end
puts temp.join
@height.times{|h|
temp = []
@vertical_lines.each do |line|
temp << "|"
temp << (line.holizonal_lines[h] ? "---" : " ")
end
puts temp.join
}
temp = []
@vertical_lines.each do |line|
temp << (line.atari ? "!!! " : " ")
end
puts temp.join
end
private
def line_writable?(first, height)
return false if first == @vertical - 1
return false if @vertical_lines[first].holizonal_lines[height]
return false if @vertical_lines[first + 1].holizonal_lines[height]
return false if first > 0 && @vertical_lines[first - 1].holizonal_lines[height]
return true
end
end
class AmidaMain
def self.main(vertical, holizonal, height)
manager = AmidaManager.new(:vertial_line => vertical,
:holizonal_line => holizonal,
:height => height)
end
end
AmidaMain.main(10, 30, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment