package demoflappybird;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class PaintPipe extends JPanel {

    private static int x1 = 500;
    private static int x2 = x1 + 140;
    private static int x3 = x1 + 140;
    private static int x4 = x2 + 140;

    private static boolean status1 = false;
    private static boolean status2 = false;
    private static boolean status3 = false;
    private static boolean status4 = false;

    private static int h1, h2, h3, h4;

    private BufferedImage OngNuocTren, OngNuocDuoi;

    public int getH1() {
        return h1;
    }

    public int getH2() {
        return h2;
    }

    public int getH3() {
        return h3;
    }

    public int getH4() {
        return h4;
    }

    public static int getX1() {
        return x1;
    }

    public static int getX2() {
        return x2;
    }

    public static int getX3() {
        return x3;
    }

    public static int getX4() {
        return x4;
    }

    public void Random() {
        Random random = new Random();

        if (status1 == false) {
            h1 = random.nextInt(200);
            status1 = true;
        }
        if (status2 == false) {
            h2 = random.nextInt(200);
            status2 = true;
        }
        if (status3 == false) {
            h3 = random.nextInt(200);
            status3 = true;
        }
        if (status4 == false) {
            h4 = random.nextInt(200);
            status4 = true;
        }
    }

    public void paintPipe(Graphics g) {

        try {
            OngNuocTren = ImageIO.read(new File("D:\\Downloads\\FlappyBird\\res\\OngnuocTren.png"));
            OngNuocDuoi = ImageIO.read(new File("D:\\Downloads\\FlappyBird\\res\\OngnuocDuoi.png"));

            g.drawImage(OngNuocTren, x1, 0, 60, h1, null);
            g.drawImage(OngNuocDuoi, x1, h1 + 100, 60, 500, null);

            g.drawImage(OngNuocTren, x2, 0, 60, h2, null);
            g.drawImage(OngNuocDuoi, x2, h2 + 100, 60, 500, null);

            g.drawImage(OngNuocTren, x3, 0, 60, h3, null);
            g.drawImage(OngNuocDuoi, x3, h3 + 100, 60, 500, null);

            g.drawImage(OngNuocTren, x4, 0, 60, h4, null);
            g.drawImage(OngNuocDuoi, x4, h4 + 100, 60, 500, null);

        } catch (IOException ex) {
            Logger.getLogger(PaintPipe.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void MovePipe() {
        x1--;
        x2--;
        x3--;
        x4--;
    }

    public void Recurrence() {
        if (x1 == -40) {
            x1 = 500;
            status1 = false;
        }
        if (x2 == -40) {
            x2 = 500;
            status2 = false;
        }
        if (x3 == -40) {
            x3 = 500;
            status3 = false;
        }
        if (x4 == -40) {
            x4 = 500;
            status4 = false;
        }
    }
}
