Advertisement
hikespect

Pole3

Jan 23rd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.80 KB | None | 0 0
  1. package nw;
  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. private int slogn;
  15.   private Podar[] gamePodar;
  16.    private Image end_game;
  17.    public Timer timerUpdate,timerDraw;
  18.  
  19.  
  20.  
  21.    public pole(int slogn)
  22.    {
  23.        this.slogn=slogn;
  24.        try
  25.        {
  26.            shapka= ImageIO.read(new File("‪C:\\Users\\User\\Desktop\\nw\\shapka.png"));
  27.        }
  28.        catch(IOException ex) {}
  29.        try
  30.        {
  31.            fon = ImageIO.read(new File("‪C:\\Users\\User\\Desktop\\nw\\fon.jpg"));
  32.        }
  33.        catch(IOException ex) {}
  34.        try
  35.        {
  36.            end_game = ImageIO.read(new File("‪C:\\Users\\User\\Desktop\\nw\\end_game.png"));
  37.        }
  38.        catch(IOException ex) {}
  39.      
  40.        gamePodar = new Podar [7];
  41.                for (int i=0;i<7;i++)
  42.                {
  43.                    try
  44.                    {
  45.     gamePodar[i] = new Podar(ImageIO.read(new File("‪C:\\Users\\User\\Desktop\\nw\\p"+i+".png")));
  46.                }
  47.    catch (IOException ex) {}
  48.                }
  49.                
  50.     timerUpdate = new Timer(3000,new ActionListener() {
  51.                  
  52.                    public void actionPerformed(ActionEvent e) {
  53.                      
  54.                    
  55.                        updateStart() ;
  56.                    }       
  57.                      
  58.                });
  59.    
  60.                    timerUpdate.start();
  61.                    timerDraw = new Timer(50,new ActionListener()  {
  62.                        public void actionPerformed(ActionEvent e) {
  63.                            repaint();
  64.                        }
  65.                    });
  66.                    timerDraw.start();
  67.    }
  68.  
  69.    
  70.  
  71.     public void paintComponent(Graphics gr)
  72.    {
  73.    super.paintComponent(gr);
  74.    gr.drawImage(fon,0,0,null);
  75.    gr.drawImage(shapka,x,465,null);
  76.           for (int i=0;i<7;i++)    
  77.           {
  78.             gamePodar[i].draw(gr);
  79.               if (gamePodar[i].act==true)
  80.               {
  81.                   if((gamePodar[i].y+gamePodar[i].img.getHeight(null))>=470) {
  82.                       if (Math.abs(gamePodar[i].x-x)>75)
  83.                       {
  84.                           gr.drawImage(end_game,300,300,null);
  85.                           timerDraw.stop();
  86.                           timerUpdate.stop();
  87.                           break;
  88.                       }
  89.                       else gamePodar[i].act=false;
  90.               }
  91.           }
  92.    }
  93.    
  94.  
  95.    }
  96.  
  97. private void updateStart()
  98. {
  99.    int kol=0;
  100.    for(int i=0;i<7;i++)
  101.    {
  102.    
  103.     if(gamePodar[i].act==false)
  104.         {
  105.        if (kol<slogn)
  106.        {
  107.            gamePodar[i].start();
  108.            break;
  109.        }
  110.        }
  111.    else kol++;
  112.     }
  113.    }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement