import java.awt.Color;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Random;

class Block {
	String name = new String();
	String color = new String();
	String shape = new String();
	int x = -1;
	int y = -1;
	Color colorcode;

	Block(String initName, String initColor, String initShape) {
		this.name = initName;
		this.color = initColor;
		this.shape = initShape;

		// 色ランダム
		colorcode = StringToColor(color);

	}

	public Color StringToColor(String colorName) {
		if (colorName.equals("red"))
			return Color.red;
		if (colorName.equals("blue"))
			return Color.blue;
		if (colorName.equals("yellow"))
			return Color.yellow;
		if (colorName.equals("green"))
			return Color.green;
		return Color.white;
	}

	boolean isHave(String element) {
		if(element.startsWith(this.name) || element.startsWith(this.color) 
				|| element.startsWith(this.shape)){
			return true;
		}
		return false;
	}

}

class BlockOp {
	static ArrayList<Block> list = new ArrayList<Block>();
	static HashSet<String> elements = new HashSet<String>();

	/**
	 * ブロックの追加
	 * 
	 * @param initName
	 * @param initColor
	 * @param initShape
	 */
	static public void addBlock(String initName, String initColor,
			String initShape) {
		list.add(new Block(initName, initColor, initShape));
		elements.add(initColor);
		elements.add(initShape);
	}

	/**
	 * 　ブロックに座標を追加する
	 * 
	 * @param blockname
	 *            追加するブロックの名前
	 * @param x
	 *            Ｘ座標
	 * @param y
	 *            　Ｙ座標
	 */
	static public void addPos(String blockname, int x, int y) {
		Block B = list.get((indexOf(blockname)));
		B.x = x;
		B.y = y;
	}

	/**
	 * nameのブロックの色または形がelementならtrue
	 * 
	 * @param name
	 * @param element
	 * @return
	 */
	public static boolean isHave(String name, String element) {
		System.out.println("isHave");
		return list.get(indexOf(name)).isHave(element);
	}

	/**
	 * nameStrのブロックのindexを返す
	 * 
	 * @param nameStr
	 * @return
	 */
	public static int indexOf(String nameStr) {
		// System.out.println("indexOf");
		for (int index = 0; index < list.size(); index++) {
			// System.out.println(index);
			if (nameStr.equals(list.get(index).name)) {
				return index;
			}
		}
		return -1;
	}

	/**
	 * x座標が衝突してたらfalse
	 * 
	 * @param x
	 * @return
	 */
	static public boolean xConflict(int x) {
		for (Block b : list) {
			if (b.x <= x && (b.x + 50) >= x)
				return false;
		}
		return true;
	}
}
