Add/Remove Food with mousePressed()

public void mousePressed(MouseEvent e) { boolean hitAFood = false; for (int i = 0; i < fList.size(); i++) { if (fList.get(i).checkMouseHit(e)) { hitAFood = true; if (e.isShiftDown()) fList.get(i).setColor(Util.randomColor()); if (e.isControlDown()) fList.remove(i); } } if (!hitAFood && !e.isControlDown() && e.isShiftDown()) fList.add(new Food( e.getX(), //x e.getY(), //y Util.random(1,5))); //size }
Goal:
- Shift + Click
- on Food → change its color
- blank space → add new Food
- Ctrl + Click
- on Food → remove clicked Food
- blank space → ignore

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.