Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. package aquarium;
  2.  
  3. import static java.lang.System.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.util.*;
  7.  
  8.  
  9. public class fish
  10. {
  11. public static void main(String[] args)
  12. {
  13. new Aquarium();
  14.  
  15. }
  16. }
  17.  
  18. class Aquarium extends Frame
  19. {
  20. private Fish jacksonFish;
  21. private boolean isRunning;
  22. public Aquarium()
  23. {
  24. isRunning = false;
  25. Color blue = new Color(34, 68, 180);
  26. setBackground(blue);
  27. setTitle("AQUARIUM");
  28. setSize(600,400);
  29. setResizable(false);
  30. setLocationRelativeTo(null);
  31.  
  32. addWindowListener(new WindowAdapter()
  33. { public void windowClosing(WindowEvent evt){System.exit(0);}});
  34. setVisible(true);
  35. jacksonFish = new Fish(240,200);
  36. start();
  37. }
  38. public void paint(Graphics g)
  39. {
  40. jacksonFish.image(g);
  41. }
  42. public void start()
  43. {
  44. isRunning = true;
  45. run();
  46. }
  47. public void run()
  48. {
  49. while(isRunning)
  50. {
  51. jacksonFish.move();
  52. repaint();
  53. delay(1);
  54. }
  55. }
  56. public static void delay(int num)
  57. {
  58. try{Thread.sleep(num*10);}
  59. catch(InterruptedException e){}
  60. }
  61.  
  62. }
  63.  
  64. class Fish
  65. {
  66. int xPos;
  67. int yPos;
  68. double xPrecision;
  69. double yPrecision;
  70. int width;
  71. int height;
  72. int speed;
  73. int direction;
  74. boolean up;
  75. boolean down;
  76.  
  77.  
  78. public Fish(int x, int y)
  79. {
  80. xPos = x;
  81. xPrecision = x;
  82. yPos = y;
  83. yPrecision = y;
  84. width = 30;
  85. height = 10;
  86. speed = 10;
  87. direction = -1;
  88. up = false;
  89. down = false;
  90. }
  91. public int getXPos()
  92. {
  93. return xPos;
  94. }
  95. public int getYPos()
  96. {
  97. return yPos;
  98. }
  99. public void setXPos()
  100. {
  101.  
  102. }
  103. public void setYPos()
  104. {
  105.  
  106. }
  107. public void move()
  108. {
  109. Random rand = new Random();
  110. int change = rand.nextInt(10);
  111. //int change = (int)rand(random()*10);
  112. if(change == 0 ) xPos++;
  113. if(change == 1 ) xPos++;
  114. if(change == 2 ) xPos++;
  115. if(change == 3 ) xPos++;
  116. if(change == 4 ) xPos++;
  117. if(change == 5 ) xPos--;
  118. if(change == 6 ) xPos--;
  119. if(change == 7 ) xPos--;
  120. if(change == 8 ) xPos--;
  121. if(change == 9 ) xPos--;
  122. }
  123. public void image(Graphics g)
  124. {
  125. }
  126. }
  127.  
  128. class Minnow extends Fish
  129. {
  130.  
  131. public Minnow()
  132. {
  133.  
  134.  
  135. }
  136. public void image(Graphics g)
  137. {
  138.  
  139. }
  140. }
Add Comment
Please, Sign In to add comment