hikespect

pole2

Dec 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package newyear;
  2.  
  3. import javax.imageio.*;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7. import java.io.*;
  8.  
  9. class pole extends JPanel
  10. {
  11.     private Image shapka;
  12.     private Image fon;
  13.     public int x = 400;
  14.     public int slogn;
  15.     public Podar[] gamePodar;
  16.     private Image end_game;
  17.     public Timer timerUpdate,timerDraw;
  18.    
  19.     public pole(int slogn)
  20.     {
  21.         this.slogn=slogn;
  22.         try
  23.         {
  24.             shapka= ImageIO.read(new File(‪C:\Users\User\Desktop\nw\shapka.png))
  25.         }
  26.         catch(IOException ex) {}
  27.         try
  28.         {
  29.             fon = ImageIO.read(new File(‪C:\Users\User\Desktop\nw\fon.jpg))
  30.         }
  31.         catch(IOException ex) {}
  32.         try
  33.         {
  34.             end_game = ImageIO.read(new File(‪C:\Users\User\Desktop\nw\end_game.png))
  35.         }
  36.         catch(IOException ex) {}
  37.        
  38.         gamePodar = new Podar [7];
  39.                 for (int i=0;i<7;i++)
  40.                 {
  41.                     try
  42.                     {
  43.      gamePodar[i] = new Podar(ImageIO.read(new file(C:\Users\User\Desktop\nw\gift.jpg)));
  44.                 }
  45.     catch (IOException ex) {}
  46.                 }
  47.                 timerUpdate = new Timer(3000,new ActionListener() {
  48.                    
  49.                     public void actionPerformed(ActionEvent e) {
  50.                        
  51.                     }
  52.                         updateStart();
  53.                        
  54.                 });
  55.                     timerUpdate.start();
  56.                     timerDraw = new Timer(50,new ActionListener()  {
  57.                         public void actionPerformed(ActionEvent e) {
  58.                             repaint();
  59.                         }
  60.                     });
  61.                     timerDraw.start();
  62.     }
  63.     public void paintComponent(Graphics gr)
  64.     {
  65.     super.paintComponent(gr);
  66.     gr.drawImage(fon,0,0,null);
  67.     gr.drawImage(shapka,x,465,null);
  68.            for (int i=0;i<7;i++)    
  69.            {
  70.                gamePodar[i].draw(gr);
  71.                if (gamePodar[i].act==true)
  72.                {
  73.                    if((gamePodar[i].y+gamePodar[i].img.getHeight(null))>=470)
  74.                        if (Math.abs(gamePodar[i].x-x)>75)
  75.                        {
  76.                            gr.drawImage(end_game,300,300,null);
  77.                            timerDraw.stop();
  78.                            timerUpdate.stop();
  79.                            break;
  80.                        }
  81.                        else gamePodar[i].act=false;
  82.                }
  83.            }
  84.     }
  85.  
  86. private void updateStart()
  87. {
  88.     int kol=0;
  89.     for(int i=0;i<7;i++)
  90.     {
  91.         if (kol<slogn)
  92.         {
  93.             gamePodar[i].start();
  94.             break;
  95.         }
  96.         }
  97.     else kol++;
  98.    
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment