Class: Tama::Animal

Inherits:
Object
  • Object
show all
Defined in:
lib/tama/animal_class.rb

Overview

Classe animal dont herite Virtualanimal. Elle contient toutes la base du tamagotchi

Direct Known Subclasses

VirtualAnimal

Constant Summary collapse

@@nbreAnimal =

Un player ne devra pas avoir plus d’un tama

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAnimal

Construteur principal



16
17
18
19
20
21
22
23
# File 'lib/tama/animal_class.rb', line 16

def initialize
    @health=$TAMA_HEALTH
    @mental=$TAMA_MENTAL
    @@nbreAnimal+=1
    puts "Creation de l'animal \n"
    @DateBirth=Chronic.parse("now")
    @Date_of_death=Chronic.parse("#{$TIME_OF_LIFE} minutes from now")
end

Instance Attribute Details

#Date_of_deathObject (readonly)

Returns the value of attribute Date_of_death.



13
14
15
# File 'lib/tama/animal_class.rb', line 13

def Date_of_death
  @Date_of_death
end

#DateBirthObject (readonly)

Returns the value of attribute DateBirth.



12
13
14
# File 'lib/tama/animal_class.rb', line 12

def DateBirth
  @DateBirth
end

#healthObject (readonly)

Returns the value of attribute health.



10
11
12
# File 'lib/tama/animal_class.rb', line 10

def health
  @health
end

#mentalObject (readonly)

Returns the value of attribute mental.



11
12
13
# File 'lib/tama/animal_class.rb', line 11

def mental
  @mental
end

Instance Method Details

#cleanObject

Fonction nettoyer le tama - le faire prendre un bain



49
50
51
52
53
54
# File 'lib/tama/animal_class.rb', line 49

def clean
    puts"Vous nettoyez votre animal \n"
    @mental +=10
    @health +=30
    return 4
end

#cureObject

Fonction soigner du tama



40
41
42
43
44
45
# File 'lib/tama/animal_class.rb', line 40

def cure
    puts"Vous soignez votre animal \n"
    @mental +=30
    @health +=60
    return 3
end

#DieOfTamaObject



73
74
75
# File 'lib/tama/animal_class.rb', line 73

def DieOfTama
    ObjectSpace.garbage_collect
end

#feedObject

Fonction manger du tama



26
27
28
29
30
# File 'lib/tama/animal_class.rb', line 26

def feed
    puts"Votre animal se nourrit \n"
    @health += 30
    return 1
end

#isAlive?Boolean

Fonction qui permet de savoir si le tama est vivant ou mort

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/tama/animal_class.rb', line 59

def isAlive?
    time_to_die=@Date_of_death
    actual_time=Chronic.parse("now")
        if actual_time > time_to_die 
            puts "Votre tama est mort"
            return false
        else
            puts "Votre tama est vivant"
            return true
        end
end

#teachObject

Fonction enseigner du tama



33
34
35
36
37
# File 'lib/tama/animal_class.rb', line 33

def teach
    puts"Votre animal apprend quelque chose \n"
    @mental += 10
    return 2
end