Created
April 25, 2014 06:50
-
-
Save kazoo04/efd3fb2c24a7c191843f to your computer and use it in GitHub Desktop.
Capsule
This file contains hidden or 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
# encoding: utf-8 | |
WIDTH = 8 | |
HEIGHT = 16 | |
class Item | |
end | |
class Capsule < Item | |
def initialize(t) | |
@type = t | |
end | |
def type | |
@type | |
end | |
def character | |
return '◯' if @type == :red | |
return '●' if @type == :yellow | |
return '◎' if @type == :blue | |
end | |
end | |
def show(field) | |
for y in 0...HEIGHT do | |
for x in 0...WIDTH do | |
if field[x][y].nil? | |
print ' ' | |
else | |
print field[x][y].character | |
end | |
end | |
puts | |
end | |
end | |
field = Array.new(WIDTH).map{ Array.new(HEIGHT, nil) } | |
field[6][10] = Capsule.new(:red) | |
field[5][12] = Capsule.new(:blue) | |
field[2][ 8] = Capsule.new(:yellow) | |
show(field) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment