package pnf;

import java.util.Random;

import javax.swing.ImageIcon;

public class Plants {
	/**植物数组*/
	static ImageIcon[] zw = new ImageIcon[4];
	ImageIcon rzw;
	int iz,w,h;
	//种植格子
	static int[] y = new int[5];
	static int[] x = new int[10];
	static boolean[][] t = new boolean[5][10];
	int ix,iy,rx,ry;
	/**植物血量*/
	int blood;
	
	static {
		for (int i = 0; i < zw.length; i++) {
			zw[i] = new ImageIcon("lib/zw"+(i+1)+".gif");
		}
		for (int i = 0; i < x.length; i++) {
			x[i] = 110+i*80;
		}
		for (int i = 0; i < y.length; i++) {
			y[i] = 191+i*100;
		}
	}
	public Plants() {//随机植物种类,位置
		Random r = new Random();
		iz = r.nextInt(zw.length);
		switch (iz) {
		case 0:
			blood = 10;
			break;
		case 1:
			blood = 10;
			break;
		case 2:
			blood = 12;
			break;
		case 3:
			blood = 68;
			break;
		}
		rzw = zw[iz];
		w = rzw.getIconWidth();
		h = rzw.getIconHeight();
		ix = r.nextInt(x.length);
		iy = r.nextInt(y.length);
		while (t[iy][ix]) {//检查是否重复使用格子
			ix = r.nextInt(x.length);
			iy = r.nextInt(y.length);
		}
		rx = x[ix];
		ry = y[iy];
		t[iy][ix] = true;
	}
	/**发射子弹*/
	public Bullet shoot(){
		if(iz == 0){
			return new Bullet(iz, rx+60,ry-68);
		}else{
			return new Bullet(iz, rx+50,ry-60);
		}
	}
}