I have an abstract class Specie, and then class Animals which extends species, and then my classes for animals (e.g. Sheep). In Animals I have a method which checks if two objects are on the same position on the map, and if the are the same type (e.g. Sheep and Sheep).
If yes it creates another Sheep. And I have problem with that I tried something like that
Specie new_specie = this;
And I have a copy consturctor in my Sheep class
public Sheep(Sheep new_sheep){
this(new_sheep.get_x(),new_sheep.get_y(), new_sheep.get_img());
}
And then save it to the array which contains all the objects
species[speciesAmount] = new_specie;
But it just saves the same object in two elements of an array
species[0]
species[2]
same object. Any ideas?
But there is another problem, I'll have more types of animals(eq. Wolf) and I can't do
new Specie(this)
because it's an abstract class.
How to make it to call the proper constructor?
edit. I solved it, I used clone() method.