public Ex24() { super(2, 2, 80, Color.red, false); setTitle("Color Sorter"); setBgColor(Color.gray); addStatusBar(25); setStatusText("Drag chips to labeled box!"); TextActor[] labels = { new TextActor("Red"), new TextActor("Yellow"), new TextActor("Green"), new TextActor("Blue") }; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { int index = 2 * x + y; addActor(labels[index], new Location(x, y)); labels[index].setLocationOffset(new Point(-15, -30)); } } for (int i = 0; i < 10; i++) { int colorId = (int) (4 * Math.random()); ChipActor chip = new ChipActor(getColor(colorId)); addActor(chip, stackLocation); chip.addMouseTouchListener(this, GGMouse.lPress | GGMouse.lDrag | GGMouse.lRelease, true); } show(); }
private boolean isOver() { for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { int index = 2 * x + y; for (Actor actor : getActorsAt(new Location(x, y), ChipActor.class)) { ChipActor chip = (ChipActor) actor; if (chip.getColor().getRGB() != getColor(index).getRGB()) return false; } } } return true; }