Created
June 2, 2012 05:11
-
-
Save kirikak2/2856695 to your computer and use it in GitHub Desktop.
minatork01 example1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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