Ruby programmer?
Posted: 07 Nov 2005, 22:09
I posted in the job postings forums and said I have ruby experience (which I do) and criptos directed me here.
I've written the majority of an IRC bot in Ruby, pretty much everying except the part that actually connects to IRC >_>
If you want look at the code (it's poorly commented, i warn you), tell me here, or PM/e-mail me.
I read on the wiki that there were plans to write a Quest script in Ruby, so I fooled around a bit, which probably won't be much help, since I have no idea what the input will be, but you can always start somewhere.
The Quest class:
I also had to make a dummy User class, which was simple
I then just ran some simple testing, and it all worked, for the record.
which returned
I've written the majority of an IRC bot in Ruby, pretty much everying except the part that actually connects to IRC >_>
If you want look at the code (it's poorly commented, i warn you), tell me here, or PM/e-mail me.
I read on the wiki that there were plans to write a Quest script in Ruby, so I fooled around a bit, which probably won't be much help, since I have no idea what the input will be, but you can always start somewhere.
The Quest class:
Code: Select all
class Quest
attr_accessor :gold, :invent, :exp
def initialize(name, gold=150, exp=150, reward=[])
#name of the quest
@name = name
#reward of gold
#default 150
@gold = gold
#reward of item, should be array, even with one item, assumed to be an ID number
#default nothing, empty array
@reward = reward
#reward of experience
#default 150
@exp = exp
end
def complete()
#what happens after the quest is completed
#user gets rewards of gold and experience
$user.gold += @gold
$user.exp += @exp
#adds each item in the reward to the users inventory
i = $user.invent.size
@reward.each { |r|
$user.invent[i] = r
i += 1
}
end
end
Code: Select all
class User
attr_accessor :gold, :invent, :exp
def initialize(name, gold=0, exp=0, invent=[])
#set gold, inventory, and experience to nothing, unless given otherwise
@name = name
@gold = gold
@invent = invent
@exp = exp
end
def to_s
s = ""
@invent.each { |i|
s << i.to_s + " "
}
return "#{@name} has #{@gold} gold, #{exp} experience, and items with IDs " + s + "."
end
end
Code: Select all
$user = User.new("Evan", 50,100,[45,63])
testQ = Quest.new("Free the chicken", 40, 90, [49])
puts $user
testQ.complete()
puts $user
$user = User.new("Evan",50,100,[45,63])
testQ = Quest.new("Survive")
puts $user
testQ.complete()
puts $user
Code: Select all
Evan has 50 gold, 100 experience, and items with IDs 45 63 .
Evan has 90 gold, 190 experience, and items with IDs 45 63 49 .
Evan has 50 gold, 100 experience, and items with IDs 45 63 .
Evan has 200 gold, 250 experience, and items with IDs 45 63 .