import java.awt.*;
import java.applet.*;

/**
*        This is a simple game, which lets you shot alien spaceships within a defined time!
*
* @title BÖRG HUNT
* @author Fabian Neumann (www.fnsite.de)
* @version 4.4b, 14.07.2000
*
* Developed with Sun Microsystems Java SDK 1.3 and Forte for Java, CE 1.0
*/

public class BHunt extends Applet
                         implements Runnable
{

  String author ="Fabian Neumann";
        String name = "Börg Hunt";
        String version = "4.4b";
        private String hh= "lkjh345";
        /** Default time to play. */
        final int zeitInSec = 30;
        /** The Thread running the game. */
        Thread runner;

        /** The spaceships taken from editable pictures.
         */
        Image[] pics =new Image[4];
        Image shot;
        Color fBlue = new Color(209,213,253);
        int  xSpot, ySpot, hitX, hitY, start, time, score, n, schonDa, dezi, chance, pts;
        /** Indicator of the skill level, used for the grade[]-array. */
        int how = 2;
        /** Maximal number of targets shown */
        int howMany = 10;

        /** Checks, whether the player hit a ship or not. Needed for showing the
         * achieved point on screen.
         */
        boolean hit =false;
        Color flash;

        final int maxN = 20;
        Ziel z[] = new Ziel[maxN];
        String grade[] = {"Tubbie-like","Just 4 Fun","Competition","Hardcore","XXXtrem"};

        int starsX[] = new int[100];
        int starsY[] = new int[100];
        Image offscreenImage;
        Graphics g;

        public void init()
        {
                resize(600,400);
                setBackground(Color.black);
                time = zeitInSec*1;
                score = 0;
                start = 0;
                schonDa = 0;
                dezi = 0;
                chance = 5;
                xSpot = 300;
                ySpot = 395;
                flash = new Color(0,0,0);

                for(int i=0; i<100;i++)
                {
                  starsX[i] = (int)(Math.random()*600);
                  starsY[i] = (int)(Math.random()*400);

                }

                setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

                offscreenImage = createImage(size().width, size().height);
                g = offscreenImage.getGraphics();

                pics[0] = getImage(getCodeBase(), "ziel0.gif");
                pics[1] = getImage(getCodeBase(), "ziel1.gif");
                pics[2] = getImage(getCodeBase(), "ziel2.gif");
                pics[3] = getImage(getCodeBase(), "ziel3.gif");
                shot = getImage(getCodeBase(), "shot.gif");

                for(int i=0; i ] "+grade[how],5,25);
                g.drawString("Time: "+time,5,40);
                g.drawString("[ + | - ]",70,40);
                g.drawString("Score: "+score,5,55);

                for(int i=0; i<100;i++)
                {
                  g.drawOval(starsX[i],starsY[i],1,1);
                }

                /*
                g.setColor(Color.red);
                g.drawRect(46,15,16,12);
                g.drawRect(71,30,15,12);
                g.drawRect(87,30,13,12);
                */

                g.setColor(Color.black);
                for(int i=0; i 0)
                {

                        if (time%1 == 0) //d.h., nur jede Sekunde
                        {

                                changeAim(); //behandelt Ziele, die schon angezeigt werden

                                addNewAim(); //fügt ggf. neue Ziele dazu

                                repaint();


                        }

                        time--;
                        try
                        {
                          Thread.sleep(1000);
                  } catch (InterruptedException e) { }
                }
        }

        public boolean clickAt(int x1,int x2,int y1,int y2,int realX, int realY)
        {
                if (realX>=x1 && realX<=x2 && realY>=y1 && realY<=y2)
                {
                        return true;
                }
                else { return false; }
        }

/* Hilfsmethoden */

        public boolean mouseMove(Event evt, int x, int y)
        {
          addSpot(x,y);
          repaint();
          return(true);
        }

        public boolean mouseDown(Event evt, int x, int y)
        {
                //yehaa = false;
                addSpot(x,y);
                hit = false;

                if (clickAt(46,62,15,27,x,y) && start==0)
                {
                        if (how == 4) {how = 0;}
                        else {how++;}

                        switch (how) //diese Abfrage ändert maximale Anzahl der erscheinenden Ziele
                        {
                        case 0: howMany = 20; chance = 2; break; //Tubbie-Like
                        case 1: howMany = 15; chance = 4; break; //Just4Fun
                        case 2: howMany = 10; chance = 5; break; //Competition
                        case 3: howMany = 8; chance = 7;  break; //Hardcore
                        case 4: howMany = 6; chance = 10; break; //XXXtrem
                        }
                        repaint();
                }
                else if (clickAt(71,86,30,42,x,y) && start==0)
                {
                        time += 1;
                        repaint();

                }
                else if (x>=87 && x<=100 && y>=30 && y<=42 && start==0)
                {
                        time -= 1;

                        /* e a s t e r  e g g */
                        if (evt.controlDown() && evt.clickCount==2 && time == 23 && start == 0)
                        {
                                System.out.println("Yehaa, you got it!");
                                yehaa = true;
                        }

                        repaint();
                }

                else if (start == 0)
                {
                        start = 1;
                        time += 1; //addiert kurz vor start noch 1 Sek dazu
                        start();
                }

                for(int i=0; iz[i].xPos && xz[i].yPos && y0
                                        && z[i].sichtbar == true
                                )
                        {
                                switch (z[i].farbe)
                                {
                                case 1:        pts = 25;
                                break;
                                case 2: pts = 15;
                                break;
                                case 3: pts = 10;
                                break;
                                case 4: pts = 5;
                                break;
                                }
                                score += pts;

                                hit = true; hitX = x-15; hitY = y+15;
                                z[i].sichtbar = false; //lässt getroffenes Ziel verschwinden
                                schonDa--;
                                break; //sorgt dafür, dass bei übereinanderliegenden Zielen, nur eins verschwindet
                        }


                }


                return true;
        }


        public boolean mouseUp(Event e, int x, int y)
        {
                xSpot = 300;
                ySpot = 395; //setzt Laser zurück
                repaint();
                return true;


        }

        /*
        public boolean mouseDrag(Event e, int x, int y)
        {
                xSpot = x;
                ySpot = y;
                repaint();

                return true;
        }
        */


        void addSpot(int x, int y)
        {
                xSpot = x;
                ySpot = y;
                repaint();
        }

        void changeAim()
        {
                for(int i = 0; i