This is a Fish Tank, where certain variants of fish can "swim" in. They move horizontally and vertically (the vertical movement is random). But one aspect is not covered yet. When two fish collide one fish just disappears and never gets shown again. I would like to cover this case in the moveFish method or in a separate method, where the larger fish covers up the smaller one until they have different positions again.
#Collision of fish in a fish tank leads to them disappearing
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Great! Please provide the code that you would like assistance with, and I'll do my best to help you.
Collision of fish in a fish tank leads to them disappearing
That's because each space can only contain one fish. If you change that to an array of fish (or in your case, a 3D array as you already have a 2D array, or a 2D array of List<Fish>), then you can store multiple fish for the same indices
Is there any way to keep it a 2D Array and just set one fish tempory to null and then print it again, when they again have different positions?
You could use a temp list for that, but that seems more cumbersome.
i fixed it like this, but theres just one "error" left. When they collide, for 1 output only the small fish gets shown, but it should be the larger one. HEres an example:| |
| ><><()><
|
|
+--------------------+
|
| ><>
|
|
+--------------------+
|
| <()><
|
|
+--------------------+
|
| <()><
|
|
+--------------------+
|
|<()><><>
|
|
+--------------------+
|
|><()> ><>
|
|
+--------------------+
I uploaded your attachments as Gist.
(Fix inside the moveFIsh() method)
Umm…since when you started learning java..just curious
2 months im a complete noob.
I have no problem to get roasted on my code, just tell me what issues you see