

import java.awt.*;
import java.applet.*;


public class InOut extends Applet implements Runnable
{
    
    MediaTracker tracker;
    int mscore;
    boolean firstDraw = true;
    String scoreString;
    Color back;
    int timer;
    int imggone;
    int fscore;
    boolean gameover;
    int imgNum = 20;
    int buckNum = 3;
    int score;
    int cow;
    Image offscrImg;
    Graphics og;
    Image funFact;
    Image img[] = new Image[imgNum];
    dragable drag[] = new dragable[imgNum];
    bucket buck[] = new bucket[buckNum];
    Image buckimg[] = new Image[buckNum];
    Image cowimg[] = new Image[3];
    String endMessage[] = new String[11];
    String loadMessage[] = new String[5];
    String inoutMessage[] = new String[imgNum];
    bucket again;
    bucket nextRow;
    Image nextImage;
    bucket startBucket;
    Image startImage;
    Image startAgain;
    String s;
    Thread runme;
    boolean show;
    int px;
    int py;
    int pw;
    int ph;
    int mult;
    
    int qx;
    int qy;
    int qw;
    int qh;
    
    int rx;
    int ry;
    int rw;
    int rh;
    
    int sx;
    int sy;
    int loopcount;
    int a = 5;
    int b = 255;
    int c = 255;
    int d = 255;
    int e = 0;
    int f  = 0;
    int h, lmc;
                            
    myCan can;
    int funx = -200;
    int funy = -200;
    boolean funyes = false;
    boolean jiggle = false;
    
    int selbuck;
    boolean cowoncan = false;
    boolean tempb = true;
    
    
    
    
    public void start()
    {
     
        //if(!tracker.checkID(0))
        //{
         
           runme = new Thread(this);
           runme.start();
            
        //}
        
    }
    
    public void stop()
    {
     
        runme.stop();
        runme = null;
        
    }
    
    
    public void run()
    {
     
        while(!show)
        {
           try{
              runme.sleep(100);
           }catch(InterruptedException e){}
           
           
           if(tracker.checkID(0, true))
           {
              show = true;
              firstDraw = true;
           }
           repaint();
           
        }

       while(show)
       {
           try{
              runme.sleep(100);
           }catch(InterruptedException e){} 
          // timer++;

           //funx = -200;
           //funy = -200;
           //funyes = false;
        if(cowoncan)
           {
            try{
              runme.sleep(1000);
           }catch(InterruptedException IE){} 
            cowoncan = false;
            cow = 0;
            repaint();
            funyes = true;
            jiggle = true;
        
           }
           if(jiggle)
           {
                try{
                    runme.sleep(50);
                }catch(InterruptedException IE){} 
                repaint();
                can.scroll(4);
           }           
           
           
        }
        
       

        
    }
    
    public void reInit()
    {
       firstDraw = true;
       mscore = 10;
       imggone = 0;
       gameover = false;
       timer = 0;
       score = 0;
       cow = 0;
       scoreString = "";

       loopcount = 0;
       for(int buckCount = 0; buckCount < buckNum; buckCount++)
       {
           buck[buckCount].reset();
       }
       
       for(int imgCount = 0; imgCount < imgNum; imgCount++)
       {
          drag[imgCount].reset();
       }
       
       setNextRow();
       startBucket.x = -200;
       startBucket.y = -200;
       

    }
    
	public void init()
	{
	    
       mscore = 10;
       scoreString = "";
       timer = 0;
       gameover = false;
       score = 0;
       cow = 0;
    
       show = false;
       imggone = 0;
       px = 100;
       py = 100;
       pw = 100;
       ph = 100;
       mult = 50;
    
       qx = 150;
       qy = 150;
       qw = 100;
       qh = 100;
    
       rx = 200;
       ry = 200;
       rw = 100;
       rh = 100;
    
       sx = 200;
       sy = 200;
       loopcount = 0;
           
       
       
       inoutMessage[6] = "Air - Cows need to breath fresh air.";
       inoutMessage[2] = "Water- A dairy cow drinks 35 gal. of water daily";
       inoutMessage[1] = "Grass- A cow will eat about 100 lbs. of grass a day.";
       inoutMessage[5] = "Hay- A cow can eat up to 25 lbs. of hay a day";
       inoutMessage[3] = "Corn - Cows eat ground corn, soybeans, wheat, barley or oats."; 
       inoutMessage[4] = "Wheat - Cows eat ground corn, soybeans, wheat, barley or oats.";
       inoutMessage[16] = "Veggies& Fruits- Cattle eat apples, broccoli, pumpkins and more."; 
       inoutMessage[13] = "Minerals and salt- Cows lick salt blocks";
       inoutMessage[12] = "Urine - A cow produces  about 3 ˝ gal. daily";
       inoutMessage[18] = "Manure- A cow can poop up to 15 times a day."; 
       inoutMessage[19] = "Heat- A cow’s temperature  is 101.5F";
       inoutMessage[11] = "Milk- Cows can produce from 4 to 20 gallons a day."; 
       inoutMessage[15] = "Meat- A steer can produce about 450 lbs. of meat"; 
       inoutMessage[9] = "Bonemeal- Cow bones may be ground for use in other livestock feed";
       inoutMessage[14] = "Leather- Cow hide (skin) makes good leather for shoes and coats.";
       inoutMessage[17] = "Cheese - Americans eat 1,000 lbs. of cheese in a lifetime.";
       inoutMessage[0] = "Pepper - Has nothing to do with a cow!";
       inoutMessage[8] = "eggs - Have nothing to do with a cow!";
       inoutMessage[7] = "Rawhide - Cow hide is used to make pet products like chew bones."; 
       inoutMessage[10] = "Margarine - Has nothing to do with a cow!";


       
       
       endMessage[0] = "Try again! That was udderly terrible. ";
       endMessage[1] = "You don't know your cow pie from your apple pie!";
       endMessage[2] = "Ooops! You just stepped in a meadow muffin!";
       endMessage[3] = "Go back to Kow Kindergarten and try again!";;
       endMessage[4] = "Not too bad. Go talk to a cow and try again.";
       endMessage[5] = "Pretty good! Brush up on your cow facts and try again.";
       endMessage[6] = "Good score! You get a big wet cow kiss.";
       endMessage[7] = "Nice work! You get the four hoof salute.";
       endMessage[8] = "Great score! A toast to you(with a big glass of milk)!";
       endMessage[9] = "Congratulations!!! You are MOOOOOOO-st excellent!!!";
       endMessage[10] = "";
       
       loadMessage[0] = "Cows are the Coolest!";
       loadMessage[1] = "The cow game is loading!";
       loadMessage[2] = "Don't MOOOO-ve it's coming!";
       loadMessage[3] = "This game is FUN!";;
       loadMessage[4] = "Cow in and out game coming up!";
       

	    
	    tracker = new MediaTracker(this);
	    
	    back = new Color(70, 170, 70);
	    offscrImg = createImage(size().width, size().height);
	    
	    again = new bucket(0, size().height-79, 77, 79);
	    startAgain = getImage(getDocumentBase(), "graphics/startagain.gif");
	    tracker.addImage(startAgain, 0);
	    
	    funFact = getImage(getDocumentBase(), "graphics/funfact.gif");
	    tracker.addImage(funFact, 0);
	    
	    can = new myCan(500, 40);
        //can.repaint();
        add(can);
	    
	    startBucket = new bucket(200, 100, 72, 57);
	    startImage = getImage(getDocumentBase(), "graphics/start.gif");
	    tracker.addImage(startImage, 0);
	   
	   	nextImage = getImage(getDocumentBase(), "graphics/next.gif");
	    tracker.addImage(nextImage, 0);
	    nextRow = new bucket(-100, -100, 72, 57);
	   
	    cowimg[0] = getImage(getDocumentBase(), "graphics/coolcow.gif");
	    tracker.addImage(cowimg[0], 0);
	    cowimg[1] = getImage(getDocumentBase(), "graphics/coolcowyes.gif");
	    tracker.addImage(cowimg[1], 0);
	    cowimg[2] = getImage(getDocumentBase(), "graphics/coolcowno.gif");
	    tracker.addImage(cowimg[2], 0);
	    
	    buckimg[0] = getImage(getDocumentBase(), "graphics/intocow.gif");
	    tracker.addImage(buckimg[0], 0);
	    buckimg[1] = getImage(getDocumentBase(), "graphics/fromcow.gif");
        tracker.addImage(buckimg[1], 0);
	    buckimg[2] = getImage(getDocumentBase(), "graphics/nocow.gif");
	    tracker.addImage(buckimg[2], 0);
	    
	    
	    buck[0] = new bucket(125, size().height-140, 112, 140);
	    buck[1] = new bucket(250, size().height-140, 112, 140);
	    buck[2] = new bucket(375, size().height-140, 112, 140);
	    
        img[12] = getImage(getDocumentBase(), "graphics/urine.gif");
        tracker.addImage(img[12], 0);
        drag[12] = new dragable(0, -200, -200, 81, 35, 1);
        
        img[18] = getImage(getDocumentBase(), "graphics/manure.gif");
        tracker.addImage(img[18], 0);
        drag[18] = new dragable(1, -200, -200, 83, 43, 1);
        
        img[2] = getImage(getDocumentBase(), "graphics/water.gif");
        tracker.addImage(img[2], 0);
        drag[2] = new dragable(2, -200, -200, 80, 51, 0);
        
        img[3] = getImage(getDocumentBase(), "graphics/corn.gif");
        tracker.addImage(img[3], 0);
        drag[3] = new dragable(3, -200, -200, 56, 89, 0);
        
        img[4] = getImage(getDocumentBase(), "graphics/wheat.gif");
        tracker.addImage(img[4], 0);
        drag[4] = new dragable(4, -200, -200, 61, 93, 0);
        
        img[5] = getImage(getDocumentBase(), "graphics/hay.gif");
        tracker.addImage(img[5], 0);
        drag[5] = new dragable(5, -200, -200, 58, 75, 0);
        
        img[6] = getImage(getDocumentBase(), "graphics/air.gif");
        tracker.addImage(img[6], 0);
        drag[6] = new dragable(6, -200, -200, 62, 53, 0);
        
        img[7] = getImage(getDocumentBase(), "graphics/bone.gif");
        tracker.addImage(img[7], 0);
        drag[7] = new dragable(7, -200, -200, 87, 58, 1);
        
        img[8] = getImage(getDocumentBase(), "graphics/eggs.gif");
        tracker.addImage(img[8], 0);
        drag[8] = new dragable(8, -200, -200, 71, 53, 2);
        
        img[9] = getImage(getDocumentBase(), "graphics/bonemeal.gif");
        tracker.addImage(img[9], 0);
        drag[9] = new dragable(9, -200, -200, 49, 58, 1);
        
        
        
        
        img[10] = getImage(getDocumentBase(), "graphics/margarine.gif");
        tracker.addImage(img[10], 0);
        drag[10] = new dragable(10, -200, -200, 67, 43, 2);
        
        img[11] = getImage(getDocumentBase(), "graphics/milk.gif");
        tracker.addImage(img[11], 0);
        drag[11] = new dragable(11, -200, -200, 43, 86, 1);
        
        img[0] = getImage(getDocumentBase(), "graphics/pepper.gif");
        tracker.addImage(img[0], 0);
        drag[0] = new dragable(12, -200, -200, 61, 73, 2);
        
        img[13] = getImage(getDocumentBase(), "graphics/salt.gif");
        tracker.addImage(img[13], 0);
        drag[13] = new dragable(13, -200, -200, 61, 73, 0);
        
        img[14] = getImage(getDocumentBase(), "graphics/shoe.gif");
        tracker.addImage(img[14], 0);
        drag[14] = new dragable(14, -200, -200, 94, 55, 1);
        
        img[15] = getImage(getDocumentBase(), "graphics/steak.gif");
        tracker.addImage(img[15], 0);
        drag[15] = new dragable(15, -200, -200, 74, 57, 1);
        
        img[16] = getImage(getDocumentBase(), "graphics/fruit.gif");
        tracker.addImage(img[16], 0);
        drag[16] = new dragable(16, -200, -200, 46, 65, 0);
        
        img[17] = getImage(getDocumentBase(), "graphics/cheese.gif");
        tracker.addImage(img[17], 0);
        drag[17] = new dragable(17, -200, -200, 56, 43, 1);
        
        img[1] = getImage(getDocumentBase(), "graphics/grass.gif");
        tracker.addImage(img[1], 0);
        drag[1] = new dragable(18, -200, -200, 61, 50, 0);
        
        img[19] = getImage(getDocumentBase(), "graphics/heat.gif");
        tracker.addImage(img[19], 0);
        drag[19] = new dragable(19, -200, -200, 58, 50, 1);
        
        
        

	}




    public void update(Graphics g)
    {
        paint(g);
        
    }
    
    void clip(Graphics g, int oldx, int oldy, int newx, int newy, int width, int height)
    {
     
        int x = Math.min(oldx, newx);
        int y = Math.min(oldy, newy);
        int w = (Math.max(oldx, newx) + width) - x;
        int h = (Math.max(oldy, newy) + height) - y;
        g.clipRect(x, y, w, h);
        
    }

    public void paint(Graphics g)
    {

       if(show)
       {
           
        
           og = offscrImg.getGraphics();
        
                
           og.setColor(back);
           og.fillRect(0, 0, size().width, size().height);
        
        
           //og.drawImage(cowimg[cow], 0, 100 ,this);
           
           
           
        
           for(int buckCount = 0; buckCount < buckNum; buckCount++)
           {
               og.drawImage(buckimg[buckCount], buck[buckCount].getX(), buck[buckCount].getY(), buck[buckCount].getW(), buck[buckCount].getH(), this);
           }
           
           for(int imgCount = 0; imgCount < imgNum; imgCount++)
           {
               og.drawImage(img[imgCount], drag[imgCount].getX(), drag[imgCount].getY(), drag[imgCount].getW(), drag[imgCount].getH(), this);   
           }
        
           

           if(cowoncan)
           {
               og.drawImage(cowimg[cow], buck[selbuck].x, buck[selbuck].y ,this);
           }else{
               og.drawImage(cowimg[cow], 0, 100 ,this);
           }
          
           
           if(gameover)
           {
                 
                 og.drawImage(cowimg[0], 0, 100 ,this);
               
                 /*
                 if(score <= 0)
                 {
                    
                   score = 0;
               
                 }else{
                
                   fscore = (int)(score * 120)/timer;
                
                 }
                 
              fscore *= 2;
              fscore += 40;
              if(fscore >= 100)
                 fscore = 100;
                 
               
              */
              mscore = (int)(score/2) - 1;
              scoreString = "YOUR FINAL SCORE IS " + String.valueOf(score)+ "/20";
             
              gameover = false;
              
              
           }
           
           og.drawImage(nextImage, nextRow.getX(), nextRow.getY(), this);
           og.drawImage(startImage, startBucket.getX(), startBucket.getY(), this);
           og.setColor(Color.blue);
           og.setFont(new Font("Dialog", Font.BOLD, 24));
           
           og.drawString(scoreString, 130, 130);
              
           
           og.drawImage(startAgain, again.getX(), again.getY(), again.getW(), again.getH(),this);
           og.setFont(new Font("Dialog", Font.BOLD, 18));
           og.setColor(Color.yellow);
           //og.drawString("Time: " + String.valueOf(timer), 21, 110);

           og.drawString("Points: " + String.valueOf(score), 18, 225);
           
           if(mscore >= 0 && mscore < 10)
           {
              og.setFont(new Font("Dialog", Font.BOLD, 15));
              og.setColor(Color.orange);
              og.drawString(endMessage[mscore], 120, 160);
           }
           
           
           if(funyes)
           {
               og.drawImage(funFact, funx, funy, this); 
               og.drawImage(funFact, funx + 398, funy, this);
               
               if(tempb)
               {
                 funx += 2;
                 funy -= 2;
                 tempb = false;

               }else{
                 funx -= 2;
                 funy += 2;
                tempb = true;

               }
             
           }

           
              
           if(firstDraw)
           {
              g.drawImage(offscrImg, 0, 0, this);
           
           }else{
            
              firstDraw = false;
              for(int imgCount = 0; imgCount < imgNum; imgCount++)
              {
                
            
                  if(dragable.draglock == imgCount)
                  {
                      clip(og, drag[imgCount].lastMouseX, drag[imgCount].lastMouseY, drag[imgCount].getX(), drag[imgCount].getY(), drag[imgCount].getW(), drag[imgCount].getH());            
                      
                  }
                  
              }
                    

              g.drawImage(offscrImg, 0, 0, this);

           }
           
           
        
       }else{
        
           
           if(firstDraw)
           {
              g.setColor(back);
              g.fillRect(0, 0, size().width, size().height);
              firstDraw = false;
           }
           
           mult = (int)(Math.random() * 10 );
           if(px < 1)
           {
              px += mult;
           }else if(px > 300){
              px -= mult;
           }else{
              if(mult < 5)
              {
                 px -= (int)(Math.random() * 10 );
              }else{
                px += (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(py < 1)
           {
              py += mult;
           }else if(py > 300){
              py -= mult;
           }else{
              if(mult < 5)
              {
                 py += (int)(Math.random() * 10 );
              }else{
                py -= (int)(Math.random() * 10 );
              }
           }

           mult = (int)(Math.random() * 10 );
           if(ph < 10)
           {
              ph += mult;
           }else if(ph > 200){
              ph -= mult;
           }else{
              if(mult < 5)
              {
                 ph += (int)(Math.random() * 10 );
              }else{
                ph -= (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(pw < 10)
           {
              pw += mult;
           }else if(pw > 200){
              pw -= mult;
           }else{
              if(mult < 5)
              {
                 pw -= (int)(Math.random() * 10 );
              }else{
                pw += (int)(Math.random() * 10 );
              }
           }
           
    
           

           
           
           
           
           mult = (int)(Math.random() * 10 );
           if(qx < 1)
           {
              qx += mult;
           }else if(qx > 300){
              qx -= mult;
           }else{
              if(mult < 5)
              {
                 qx += (int)(Math.random() * 10 );
              }else{
                qx -= (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(qy < 1)
           {
              qy += mult;
           }else if(qy > 300){
              qy -= mult;
           }else{
              if(mult < 5)
              {
                 qy += (int)(Math.random() * 10 );
              }else{
                qy -= (int)(Math.random() * 10 );
              }
           }

           mult = (int)(Math.random() * 10 );
           if(qh < 10)
           {
              qh += mult;
           }else if(qh > 300){
              qh -= mult;
           }else{
              if(mult < 5)
              {
                 qh -= (int)(Math.random() * 10 );
              }else{
                 qh += (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(qw < 10)
           {
              qw += mult;
           }else if(qw > 300){
              qw -= mult;
           }else{
              if(mult < 5)
              {
                 qw -= (int)(Math.random() * 10 );
              }else{
                qw += (int)(Math.random() * 10 );
              }
           }


           
           
           
           
           
           
                      mult = (int)(Math.random() * 10 );
           if(rx < 1)
           {
              rx += mult;
           }else if(rx > 300){
              rx -= mult;
           }else{
              if(mult < 5)
              {
                 rx += (int)(Math.random() * 10 );
              }else{
                rx -= (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(ry < 1)
           {
              ry += mult;
           }else if(ry > 300){
              ry -= mult;
           }else{
              if(mult < 5)
              {
                 ry += (int)(Math.random() * 10 );
              }else{
                ry -= (int)(Math.random() * 10 );
              }
           }

           mult = (int)(Math.random() * 10 );
           if(rh < 10)
           {
              rh += mult;
           }else if(rh > 300){
              rh -= mult;
           }else{
              if(mult < 5)
              {
                 rh -= (int)(Math.random() * 10 );
              }else{
                rh += (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(rw < 10)
           {
              rw += mult;
           }else if(rw > 300){
              rw -= mult;
           }else{
              if(mult < 5)
              {
                 rw -= (int)(Math.random() * 10 );
              }else{
                rw += (int)(Math.random() * 10 );
              }
           }
           
           
           
           
           
           
           
           mult = (int)(Math.random() * 10 );
           if(rw < 10)
           {
              rw += mult;
           }else if(rw > 300){
              rw -= mult;
           }else{
              if(mult < 5)
              {
                 rw -= (int)(Math.random() * 10 );
              }else{
                 rw += (int)(Math.random() * 10 );
              }
           }
           
           
           
           mult = (int)(Math.random() * 10 );
           if(sy < 100)
           {
              sy += mult;
           }else if(sy > 200){
              sy -= mult;
           }else{
              if(mult < 5)
              {
                 sy += (int)(Math.random() * 10 );
              }else{
                sy -= (int)(Math.random() * 10 );
              }
           }
           
           mult = (int)(Math.random() * 10 );
           if(sx < 100)
           {
              sx += mult;
           }else if(sx > 200){
              sx -= mult;
           }else{
              if(mult < 5)
              {
                 sx += (int)(Math.random() * 10 );
              }else{
                sx -= (int)(Math.random() * 10 );
              }
           }
           
           
 
          
          if(mult <= 3)
          {
             g.setColor(Color.blue);
             g.drawOval(rx, ry, rw, rh);
             g.setColor(Color.green);
             g.drawOval(qx, qy, qw, qh);
             g.setColor(Color.red);
             g.drawOval(px, py, pw, ph);

          }else if(mult <= 6 && mult > 3){
            g.setColor(Color.blue);
            g.drawOval(rx, ry, rw, rh);
            g.setColor(Color.red);
            g.drawOval(px, py, pw, ph);
            g.setColor(Color.green);
            g.drawOval(qx, qy, qw, qh);
            
          }else{
            g.setColor(Color.red);
            g.drawOval(px, py, pw, ph);
            g.setColor(Color.blue);
            g.drawOval(rx, ry, rw, rh);
            g.setColor(Color.green);
            g.drawOval(qx, qy, qw, qh);
            
            
          }
          
            loopcount++;
            if(loopcount > 15)
            {
               loopcount = 0;
               a = (int)(Math.random() * 36);
               b = (int)(Math.random() * 255);
               c = (int)(Math.random() * 255); 
               d = (int)(Math.random() * 255);
               e = (int)(Math.random() * 255);
               f = (int)(Math.random() * 255);
               h = (int)(Math.random() * 255);
               lmc = (int)(Math.random() * 5);
               
               
            g.setFont(new Font("Dialog", Font.BOLD, 42));
            
            g.setColor(new Color(e, f, h));
            
            g.fillOval(46, 96, 407, 148);
            
            g.setColor(new Color( b, c, d));
            
            g.fillOval(50, 100, 400, 141);
            g.setColor(new Color(e, f, h));
            g.drawString("Please Wait!", 110, 160);
            g.setFont(new Font("Dialog", Font.BOLD, 15));
            g.drawString(loadMessage[lmc], 130, 200);
            }
            
 
          
          
           

        
       }

    }
    
    public void setNextRow()
    {
        int times = 1;
        for(int count = imggone; count < imggone + 4; count ++)
        {
            drag[count].x = (100 * times) + 10;
            times++;
            drag[count].y = 90;
            
        }
        
        nextRow.x = -200;
        nextRow.y = -200;
        
    }
    
    
    public boolean mouseUp(Event e, int x, int y)
    {
        
      if(startBucket.IsInside(x, y))
      {
         can.setCan("");
         setNextRow();
         startBucket.x = -200;
         startBucket.y = -200;
         timer = 0;
      }
      if(nextRow.IsInside(x, y))
      {
       
        setNextRow();
        
      }
      
      for(int buckCount = 0; buckCount < buckNum; buckCount++)
      {        
        for(int imgCount = 0; imgCount < imgNum; imgCount++)
        {
            if(drag[imgCount].IsInside(x, y))
            {

                if(buck[buckCount].IsInside(x, y))
                {
                    if(drag[imgCount].InOut != buckCount)
                    {
                        //score -= 1;
                       
                        can.setCan(inoutMessage[imgCount]);
                        cowoncan = true;
                        funx = 3;
                        funy = 10;
                        //funyes = true;
                        //jiggle = true;
                        selbuck = buckCount;

                        cow = 2;
                        
                    }else{
                        score += 1;
                        cowoncan = true;
                        can.setCan(inoutMessage[imgCount]);
                        funx = 5;
                        funy = 10;
                        //funyes = true;
                        //jiggle = true;
                        selbuck = buckCount;
                        
                        cow = 1;
                        
                    }
                    
                    
       
                    
           
                    
                    
                    

                    drag[imgCount].setPos(-100, -100);
                    imggone++;
                    
                    if(imgNum == imggone)
                    {
                        gameover = true;
                        firstDraw = true;
                    }
                    
                    if((imggone % 4) == 0 && !gameover)
                    {
                        nextRow.x = 250;
                        nextRow.y = 125;
                    }else{
                        nextRow.x = -200;
                        nextRow.y = -200;
                    }
                    
                    

                }
            
            }
            
        }
      }
      repaint();

      return true;
        
    }
    
    public boolean mouseDown(Event e, int x, int y)
    {
        can.setCan("");
        funyes = false;
        jiggle = false;
        repaint();
        can.repaint();
        for(int imgCount = 0; imgCount < imgNum; imgCount++)
        {
            if(drag[imgCount].IsInside(x, y))
            {
                 drag[imgCount].setMouseDown(x, y);
            }
        }

        if(again.IsInside(x, y))
          reInit();
        return true;
        
    }
    
    int dragc = 0;
    
    public boolean mouseDrag(Event e, int x, int y)
    {

        dragc++;
        if(dragc == 5)
        {
            dragc=0;
        }
        cow = 0;
        for(int imgCount = 0; imgCount < imgNum; imgCount++)
        {
            if(drag[imgCount].IsInside(x, y))
            {
                drag[imgCount].setPos(x, y);
                if(dragc == 4)
                {
                    repaint();
                }
            }
        }
        

        
        return true;
        
    }

}


class dragable extends bucket
{
 
    public static int draglock;
    public int InOut, lastMouseX, lastMouseY, id;
    
    dragable(int id, int x, int y, int w, int h, int InOut)
    {
              
        super(x, y, w, h);
        this.InOut = InOut;
        this.id = id;
    }
    
    
    void setMouseDown(int downX, int downY)
    {

          draglock = id;
          lastMouseX = downX;
          lastMouseY = downY;

        
    }
    void setPos(int newMouseX, int newMouseY)
    {     
        
        if(draglock == id)
        {
           x += newMouseX - lastMouseX;
           y += newMouseY - lastMouseY;
        
           lastMouseY = newMouseY;
           lastMouseX = newMouseX;
        }
        
    }
    
    
}

class bucket
{
 

    public int x, y, w, h;
    public int ox, oy, ow, oh;
    
    bucket(int x, int y, int w, int h)
    {
              
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        ox = x;
        oy = y;
        ow = w;
        oh = h;
    }
    
    void reset()
    {
        x = ox;
        y = oy;
        w = ow;
        h = oh;  
        
    }
    
    int getW()
    {
       return w; 
    }
    
    int getH()
    {
       return h; 
    }
    
    int getX()
    {
       return x; 
    }
    
    int getY()
    {
       return y; 
    }
    
    boolean IsInside(int mx, int my)
    {

        if(mx >= x && mx < (x + w) && my >= y && my <= (y + h))
        {
            
            return true;
            
        }else{
            
            return false;
            
        }
        
    }
    
}

class myCan extends Canvas
{
    
    private String curString;
    int x, y;
    Color mblue;
    //boolean rb;
    int ccount = 0;
    
    Color carr[] = new Color[6];

    
    myCan(int w, int h)
    {
     
        carr[0] = new Color(170, 70, 170);
        carr[1] = new Color(255, 255, 255);
        carr[2] = new Color(250, 150, 50);
        carr[3] = new Color(225, 25, 25);
        carr[4] = new Color(25, 25, 225);
        carr[5] = new Color(0, 0, 0);
        //resize(w, h);
        resize(290, 40);
        mblue = new Color(70, 170, 70);
        //mred = new Color(170, 70, 70);
        //rb = true;

        
    }
    
    
    public void setCan(String s)
    {
        
        curString = s;
        x = 10;
        y = 20;
        ccount++;
        if (ccount > 5)
        {
            ccount = 0;
        }
        //rb = !rb;

        
    }
    
    public void scroll(int amount)
    {
        
        x -= amount;
        this.repaint();

        
    }
    
    public void update(Graphics g)
    {
        
        this.paint(g);       
        
    }
 
    public void paint(Graphics g)
    {
        //if(rb)
        //{
           //g.setColor(mblue);
        //}else{
           //g.setColor(mred); 
        //}
        g.setColor(mblue);
        g.fillRect(0, 0, 300, 50);
        g.setColor(carr[ccount]);
        g.setFont(new Font("Dialog", Font.BOLD, 12));
        //g.clipRect(x, y, 300, 50);
        g.drawString(curString, x, y); 


     
    }
    
    
    
}


