-
-
Save apeiros/cb0fab5c4d7ffd9309da to your computer and use it in GitHub Desktop.
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
class EnemyClass | |
def self.deserialize(string) | |
id, name, attack, defense, hp = new(*en.split("/")) | |
new( | |
Integer(id, 10), | |
name, | |
Integer(attack, 10), | |
Integer(defense, 10), | |
Integer(jp, 10) | |
) | |
end | |
attr_reader :name | |
def initialize(id, name, attack, defense, hp) | |
@id = id | |
@name = name | |
@attack = attack | |
@defense = defense | |
@hp = hp | |
end | |
end | |
module EnemyModule | |
def self.getEnemies | |
enemy_array = [] # variable declerations need to be within the method | |
allEnemies = [] | |
enemies = open(ENEMY_URL) | |
enemies.each_line {|line| enemy_array.push(line)} | |
# create allEnemy array of EnemyClass objects | |
enemy_array.each {|en| allEnemies << EnemyClass.deserialize(en) } | |
allEnemies.each { |x| puts x } | |
return allEnemies | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment