I have a 2D array grid on which a couple of runnable vehicle objects (an 'x' and an 'o') are randomly placed. The grid repeatedly prints to console, and the x/y coordinates of the vehicle objects updates on their threads which gives the impression of the vehicles animating across the grid-lanes.
However, I'm stuck on how to make the vehicle objects respawn once they've reached the end of the grid. Any ideas how I can achieve this? Here's a screen shot and the code:
For a quick and dirty fix, you must change two things in the overridden run-method.
First: remove the continuation condition in the for-loop (i < g.getColumns()). As you have it now, it only runs for every column and then it stops, leaving the 'o 'and 'x' where they are.
Second: if y becomes > grid.getColumns(), reset it to 0.
I hate signatures!
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop