Advertisement
Guest User

Untitled

a guest
Apr 7th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. class shell {
  6.     // Факт того что снаряд на поле
  7.     public boolean shells_on_board;
  8.     // Таймер
  9.     public Timer new_shell_Timer;
  10.     //Переменные координат зарядов
  11.     public int shell_x1, shell_x2, shell_y1, shell_y2;
  12.     //Переменная картинки заряда
  13.     public Image image_shell;
  14.    
  15.     // Конструктор класса
  16.     public shell(Image img_shell, final int LocationX1, final int LocationX2,
  17.             final int LocationY1, final int LocationY2) {
  18.         //Получаем все в локальные переменные
  19.         shell_x1 = LocationX1;
  20.         shell_x2 = LocationX2;
  21.         shell_y1 = LocationY1;
  22.         shell_y2 = LocationY2;
  23.         image_shell=img_shell;
  24.        
  25.         new_shell_Timer = new Timer(1, new ActionListener() {
  26.             public void actionPerformed(ActionEvent Event) {
  27.                 if (shell_y1 > 0) {
  28.                    
  29.                     shells_on_board = true;
  30.                     shell_y1 -= 1;
  31.                     shell_y2 -= 1;
  32.                    
  33.                 } else {
  34.                     shells_on_board = false;
  35.                 }
  36.                
  37.             }
  38.         });
  39.         new_shell_Timer.start();
  40.        
  41.     }
  42.  
  43.     public void paintComponent(Graphics gr) {
  44.         System.out.println(shell_y1);
  45.         if (shells_on_board == true) {
  46.             gr.drawImage(image_shell, shell_x1, shell_y1, null);
  47.             gr.drawImage(image_shell, shell_x2, shell_y2, null);
  48.         } else {
  49.             new_shell_Timer.stop();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement