import java.awt.*;
import java.awt.image.*;

public class Playfield extends Raster {

  private Sprite[] sprite;
  private int nSprites;
  
  /////////////   CONSTRUCTORS   //////////////////////
  
  // zero argument constructor for future expansion 
  public Playfield() { ;}

  // constructor with background image and #sprites as parameters 
  // this constructor uses the base class's constructor to initialize itself. 
  public Playfield( Image imgBgnd, int numSprites ) {
     super( imgBgnd );
     nSprites =  numSprites;
     sprite = new Sprite[ nSprites ];
  }

  ///////////////  METHODS  ///////////////////////////

  // add sprites  to playfield 
  public void addSprite( int i, Sprite s ) {
    // if( i < nSprites ) 
    sprite[i] = s;
    //else throw "some kind of exception "
    return;
  }

 
  // draw playfield with sprites 
  public Image Draw( Component c ) {
    //below: paint (sprite0 on bkgrnd), then [sprite1+(sprite0+bkgrnd)]
    for( int i=0; i < nSprites; i++ ) {
      sprite[i].Draw( this );
    }
    return this.toImage(c);   
  }//DRAW
  

 public void setImage( Image img ) {
    try {
      PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, true);
      if (grabber.grabPixels()) {
	width = grabber.getWidth();
	height = grabber.getHeight();
	pixel = (int []) grabber.getPixels();
      }
    } catch (InterruptedException e) {
    }
    return;
 }

} //CLASS PLAYFIELD
