As my first Ruby endeavour, I have decided to make
a small text based RPG.
This is probably a huge undertaking for a noob.
I have made like, 3 or 4 classes so far.
This is the character generation stage, and for some reason,
it doesn’t like me. It won’t work. Well, I’ll
post my code so far(Yes, ChooseClass is incomplete.), and could someone
tell me what I have done wrong and how to make it better?
Here’s my code:
class Game_Start
attr_accessor :strength
attr_accessor :defense
attr_accessor :agility
attr_accessor :evasion
attr_accessor :hp
attr_accessor :mp
attr_accessor :max
attr_accessor :min
attr_accessor :name
def initialize
hp.max = 100
hp.min = 1
hp.name = ‘HP’
mp.max = 100
mp.min = 1
mp.name = ‘MP’
strength.max = 20
strength.min = 1
strength.name = ‘Strength’
defense.max = 20
defense.min = 1
defense.name = ‘Defense’
agility.max = 20
agility.min = 1
agility.name = ‘Agility’
evasion.max = 20
evasion.min = 1
evasion.name = ‘Evasion’
$hero_class = [‘Warrior’, ‘Mage’, ‘MageWarrior’]
end
end
#That defines all the normal abilities in the game. Soon, in version 2,
I will add special abilities.
class Roll < Game_Start
def initialize(ability)
maximum = ability.max - 1
roll = rand(maximum)
roll = roll + 1
print ability.name
print ': ’
print roll
puts ‘’
end
end
class RollAbilities < Game_Start
strength = Roll.new(strength)
defense = Roll.new(defense)
agility = Roll.new(agility)
evasion = Roll.new(evasion)
puts ‘Would you like to keep these stats?’
puts ‘y/n’
input = gets
if input == ‘y’
$strength = strength
$defense = defense
$agility = agility
$evasion = evasion
puts ‘-----’
ChooseName.new
else
RollAbilities.new
end
end
class ChooseName
def initialize
puts ‘Please Select your Name, by typing it in now.’
name = gets
if name == ‘’
puts ‘Sorry, that name is invalid’
else
print ‘Are you sure that ’
print name
print ’ is a good name?’
print ’ y/n ’
ans = gets
if ans == ‘y’
$name = name
ChooseClass.new
else
puts ‘Okay, choose again.’
puts ‘-----’
ChooseName.new
end
end
puts ‘Here is your information so far:’
puts 'Name: ’
puts $name
puts 'Strength: ’
puts $strength
puts 'Defense: ’
puts $defense
puts 'Agility: ’
puts $agility
puts 'Evasion: ’
puts $evasion
end
end
class ChooseClass < Game_Start
def initialize
puts ‘Please select a class to view information on.’
puts ‘Classes are:’
puts $hero_class
end
end
There it is.
As you may have guessed, it runs in the Ruby Console window.
Can anyone help me? I need help desperately.