Platform- java applets with multithreading OS- Ubuntu There are 2 arrays x and y with 100 elements each. These arrays store the coordinates of an snake. The run method is used to manipulate the coordinates as a user presses a key using Java's keylisteners...the keys can be W A S D or arrow keys. Finally using repaint method in the run I am painting the applet screen with ovals at the modified coordinates. All this is on a single thread and works fine. The problem starts when I do it on multiple threads for 2 users. Requirement- 2 users controlling 2 independent snakes on same applet screen using multiple threads. Question 1- Is it possible? Do I have to use 2 separate sets of arrays like x1 y1 and x2 y2 or multithreading will do that for me(allocate separate storage for each thread)? Question 2- I do not want to modify the run method...Just the run method should work on different arrays for both players...player 1 uses WASD and player 2 arrow keys. Question 3- How should the paint method be modified?
Aucun commentaire:
Enregistrer un commentaire