Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. |<--- this code is formatted to fit into 80 columns --->|
  10. |<--- this code is formatted to fit into 80 columns --->|
  11. |<--- this code is formatted to fit into 80 columns --->|
  12. Timer.java
  13. Part of the Spacewar system.
  14. */
  15. package spacewar;
  16. class Timer extends Thread {
  17. private final static int TICK_PERIOD = 40; // time between ticks in millis
  18. private Game game;
  19. Game getGame() { return game; }
  20. Timer (Game theGame) {
  21. super("Timer");
  22. game = theGame;
  23. }
  24. public void run() {
  25. long t1, tdiff;
  26. while (true) {
  27. t1 = System.currentTimeMillis();
  28. getGame().clockTick();
  29. tdiff = System.currentTimeMillis() - t1;
  30. if (tdiff < TICK_PERIOD) {
  31. try {
  32. sleep (Math.max(0 , TICK_PERIOD - tdiff));
  33. }
  34. catch (InterruptedException e) { }
  35. }
  36. }
  37. }
  38. }