

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Color;

public class Box {
   
   
   private static final int WIDTH = 90;
   private static final int HEIGHT = 90;
   
   int x = (int) (Math.random()*2000)+1 ;
   int y =(int) (Math.random()*2000)+1  ;
   int xa = 1;
   int ya = 1;
   private Game game;

   public Box(Game game) {
      this.game= game;
   }

   void move() {
      if (x + xa < 0)
         xa = 1;
      if (x + xa > game.getWidth() - WIDTH)
         xa = -1;
      if (y + ya < 0)
         ya = 1;
         
      if (y + ya > game.getHeight() - HEIGHT)
         ya = -1;
   
       	
      if (collision()){
         game.gameOver();
      }
      x = x + xa;
      y = y + ya;
   }
   
      

   private boolean collisionball() {
      return game.ball.getBounds().intersects(getBounds());
   }
   private boolean collision() {
      return game.player.getBounds().intersects(getBounds());
   }

   public void paint(Graphics2D g) {  
      g.setColor(Color.red);  
      g.fillRect(x,y,WIDTH, HEIGHT);
   
   }
	
   public Rectangle getBounds() {
      return new Rectangle(x, y, WIDTH, HEIGHT);
   }
}