-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodereuse.js
More file actions
90 lines (73 loc) · 1.34 KB
/
codereuse.js
File metadata and controls
90 lines (73 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const dog = {
name: 'Scout',
breed: ['Husky', 'German Shepherd'],
age: 4,
happiness: 50,
hunger: 10,
energy: 100,
};
dog['feed'] = function (food) {
if(dog.hunger - food > 0) {
dog.hunger -= food;
} else {
dog.hunger = 0;
}
}
dog['play'] = function(time) {
if(dog.happiness + time < 100) {
dog.happiness += time;
} else {
dog.happiness = 100;
}
if(dog.energy - time > 0) {
dog.energy -= time;
} else {
dog.energy = 0;
}
}
dog['nap'] = function(time) {
if(dog.energy + time < 100) {
dog.energy += time;
} else {
dog.energy = 100;
}
}
//Psuedoclassical
var Dog = function(name, breed, age, happiness, hunger, energy) {
var obj = Object.create(Dog.prototype);
this.name= name;
this.breed= breed;
this.age= age;
this.happiness= happiness;
this.hunger= hunger;
this.energy= energy;
}
Dog.prototype.feed = function (food) {
if(this.hunger - food > 0) {
this.hunger -= food;
} else {
this.hunger = 0;
}
}
Dog.prototype.play = function(time) {
if(this.happiness + time < 100) {
this.happiness += time;
} else {
this.happiness = 100;
}
if(this.energy - time > 0) {
this.energy -= time;
} else {
this.energy = 0;
}
}
Dog.prototype.nap = function(time) {
if(this.energy + time < 100) {
this.energy += time;
} else {
this.energy = 100;
}
}
Mobey = new Dog("Mobey", "Pit/Lab", 6, 9, 9, 2);
Mobey.feed(1);
Mobey.play(3)