Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- /**
- *
- * @author Sergey
- */
- public class Pole extends JPanel{
- //
- private Image shapka;
- private Image fon;
- public int x = 400;
- private int slogn;
- private Podar[] gamePodar;
- private Timer timerUpdate, timerDraw;
- public Pole(int slogn){
- this.slogn = slogn;
- this.shapka = Game.loadImage("c:\\game\\shapka.png");
- //this.shapka = Game.loadImage("c:\\game\\p0.png");
- this.fon = Game.loadImage("c:\\game\\fon.jpg");
- //
- gamePodar = new Podar[7];
- for(int i = 0; i < gamePodar.length; i++){
- gamePodar[i] = new Podar(Game.loadImage("c:\\game\\p" + i + ".png"));
- }
- //
- timerUpdate = new Timer(3000, new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e){
- updateStart();
- }
- });
- timerUpdate.start();
- //
- timerDraw = new Timer(50, new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e){
- repaint();
- }
- });
- timerDraw.start();
- }
- //
- private void updateStart(){
- //
- int kol = 0;
- for(int i = 0; i < gamePodar.length; i++){
- if(gamePodar[i].act){
- kol++;
- }else if(kol<slogn){
- gamePodar[i].start();
- break;
- }
- }
- }
- //
- @Override
- public void paintComponent(Graphics gr){
- //
- super.paintComponent(gr);
- gr.drawImage(fon, 0, 0, null);
- gr.drawImage(shapka, x, 465, null);
- //
- for(int i = 0; i < gamePodar.length; i++){
- gamePodar[i].draw(gr);
- if(gamePodar[i].act){
- if(gamePodar[i].y + gamePodar[i].img.getHeight(null) >= 470){
- if(Math.abs(gamePodar[i].x - x) > 75){
- //
- gr.setFont(new Font("Arial", Font.BOLD, 24));
- gr.setColor(Color.red);
- gr.drawString("Игра закончена!", 300, 300);
- timerDraw.stop();
- timerUpdate.stop();
- break;
- }else{
- gamePodar[i].act = false;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement