If you call “aiPlayer = new Ai(img, img2, numPlayers);” in/through the constructor of Game, or any kind of "new Ai()…, it will loop.
Else it looks ok.
(As a side note, having the “Ai” extending a “Game” doesnt sound “right”, if you need to access Game in Ai, just pass the game object to Ai, or make it static)
Not calling it in the constructor. I don’t see it duplicating data but it the trace is keeps looping the output of some of the other functions in the class.
Do you have a function call in the Game constructor which indirectly calls new Ai()?
Else “minify” your game constructor(closing bracket after super) and see what happens.
First of all I want to thank you for the help. Second… I am not familiar on how to ‘minify’.
I am not calling it directly in the constructor but it is in the chain of the functions that are called when the game class is called. The Ai class is being called about two levels deep. I guess you could say the constructor is calling it ‘directly’. What I have noticed though is that while the trace is behaving as if it’s in a loop it does not trace out continuously. There is a delay before it traces out the output again. Does that make sense?
What i ment was to close the Game constructor directly after the super(); call.
You would see it wouldnt loop then anymore.
The moment you call “new AI()” somehow through the Game constructor, be it directly in it, or through other functions/classes which you call/create in it - it will loop.
To get a Game-object, the whole constructor needs to run/finish, with all the function/class calls inside.
In the moment there is a “new Ai” call involved, it loops because to create a AI-object the AI and Game constructor need to run.