Class: GamesAndRpgParadise::MightAndMagic::Character

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/games/might_and_magic/character.rb

Overview

GamesAndRpgParadise::MightAndMagic::Character

Direct Known Subclasses

Hero

Constant Summary collapse

AVAILABLE_RACES =
#

AVAILABLE_RACES

This Array is incomplete - I think a few races are missing.

#
%w(
  human
  elf
  dwarf
  lizard
)

Instance Method Summary collapse

Constructor Details

#initialize(hero_type = '', hero_race = 'rand', hp_bonus = 0, set_number_of_attacks_already = nil) ⇒ Character

#

initialize

#


33
34
35
36
37
38
39
40
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 33

def initialize(
    hero_type = '',
    hero_race = 'rand',
    hp_bonus  = 0,
    set_number_of_attacks_already = nil
  )
  reset
end

Instance Method Details

#alive=(i) ⇒ Object

#

alive=

#


130
131
132
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 130

def alive=(i)
  @alive = i
end

#alive?Boolean Also known as: alive

#

alive?

#

Returns:

  • (Boolean)


123
124
125
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 123

def alive?
  @alive
end

#do_dieObject

#

do_die

Use this event when a character dies.

#


116
117
118
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 116

def do_die
  @alive = false # is now dead.
end

#hero_type?Boolean Also known as: type?, type

#

hero_type?

#

Returns:

  • (Boolean)


144
145
146
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 144

def hero_type?
  @hero_type
end

#resetObject

#

reset (reset tag)

#


45
46
47
48
49
50
51
52
53
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 45

def reset
  # ======================================================================= #
  # === @alive
  #
  # Initially a character is alive, thus the following variable
  # is set to true.
  # ======================================================================= #
  @alive = true
end

#select_random_raceObject

#

select_random_race

Will set a random race to @race.

#


60
61
62
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 60

def select_random_race
  @race = AVAILABLE_RACES.sample
end

#set_age(i) ⇒ Object

#

set_age

#


103
104
105
106
107
108
109
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 103

def set_age(i)
  case i
  when :random
    i = (16..40).to_a.shuffle[0]
  end
  @age = i.to_s
end

#set_gender(i) ⇒ Object

#

set_gender

#


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 87

def set_gender(i)
  case i.to_s
  when 'random'
    case rand(2)
    when 0
      i = 'female'
    when 1
      i = 'male'
    end
  end
  @gender = i.to_s
end

#set_hero_type(i = :random) ⇒ Object Also known as: set_type

#

set_hero_type

#


137
138
139
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 137

def set_hero_type(i = :random)
  @hero_type = i
end

#set_level(i) ⇒ Object

#

set_level

This must be an Integer - we only have level 1, 2, 3 and so forth, and never 2.5 or “2”.

#


80
81
82
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 80

def set_level(i)
  @level = i.to_i
end

#set_number_of_attacks(i) ⇒ Object

#

set_number_of_attacks

How many attacks a given character has. Barbarians have the highest number of attacks in this regard.

#


70
71
72
# File 'lib/games_and_rpg_paradise/games/might_and_magic/character.rb', line 70

def set_number_of_attacks(i)
  @n_attacks = i
end