-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreature.java
More file actions
88 lines (79 loc) · 1.92 KB
/
Creature.java
File metadata and controls
88 lines (79 loc) · 1.92 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
import java.util.BitSet;
public class Creature extends ScreenObject implements Cloneable{
private Genome genome;
private int foodEaten;
private int foodEatenAll;
private int moveCount;
// constructors
public Creature() {
super();
this.genome = new Genome();
}
public Creature(Genome genome){
super();
this.genome = genome;
}
public Creature(BitSet DNA) {
super();
this.genome = new Genome(DNA);
}
// setters
public void setGenome(Genome genome) {
this.genome = genome;
}
public void moved() {
moveCount++;
}
// getters
public Genome getGenome() {
return this.genome;
}
public int getFoodCount(){
return foodEaten;
}
public int getFoodCountAll() {
return foodEatenAll;
}
public int getMoveCount() {
return moveCount;
}
// Methods
public Creature[] reproduce() {
try {
int howManyRepoduce = 1;
Creature[] copies = new Creature[howManyRepoduce];
for (int i = 0; i < howManyRepoduce; i++) {
copies[i] = (Creature)this.clone();
}
return copies;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
// hunger
public void ateFood() {
foodEaten++;
foodEatenAll++;
}
public void clearFood(){
foodEaten = 0;
}
@Override
public String toString() {
return genome.getDNA().toString();
}
public Object clone() {
try {
Creature clone = (Creature)super.clone();
clone.genome = (Genome)genome.clone();
clone.foodEaten = 0;
clone.foodEatenAll = this.foodEatenAll;
clone.moveCount = 0;
return clone;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
}