I am currently working on a project which requires linking two mouse events. The game consists in comparing two moving balloons from lots of balloons on the screen. The instructions are:
If the translation of the word is correct, the balloons fade away and I don't lose lives ("lives" are rectangles on a HBox
), otherwise I lose lives and the balloons fade away.
The other thing that came to my mind was:
The program should know I have clicked those two balloons. Then I could use a method to compare the balloons to check if the translation was wrong or right and make them fade away.
You should add an EventHandler to each baloon and keep track if is the first or second ballon using another variable. Something like this:
public class ViewController {
private String savedStr;
public void init() {
for (Baloon baloon : baloons) {
baloon.setOnMouseClicked(event -> {
if (savedStr == null) { // Mouse Event 1
savedStr = baloon.getString());
} else { // Mouse Event 2
checkTranslation(savedStr, baloon.getString());
savedStr = null;
}
}
}
}
}