Originally Posted by
pianorain
I would keep track of the color of the last firework selected. Note the hexadecimal for each color of the rockets: red (0xff0000), green (0x00ff00), blue (0x0000ff), and white (0xffffff). If you require that bitwise-and of the color of the last firework selected and the next selected rocket be non-zero, you should achieve the effect you're looking for.
For example, I first select a red rocket. My last_color = 0xff0000.
If I try to select a blue rocket, I see that I can't because my last_color and selected_color don't "match". 0xff0000 & 0x0000ff == 0.
If I select another red rocket, last_color and selected_color obviously "match". 0xff0000 & 0xff0000 == 0xff0000. last_color = 0xff0000.
If I select a white rocket, last_color and selected_color still "match". 0xff0000 & 0xffffff == 0xff0000. last_color = 0xffffff.
Now I can select any color rocket, because any of the colors will "match" with the white rocket. I'll select a blue rocket. 0xffffff & 0x0000ff == 0x0000ff. last_color = 0x0000ff.
Now if I try to select a red rocket, it no longer "matches". 0x0000ff & 0xff0000 == 0.
However, I can still select a blue rocket. 0x0000ff & 0x0000ff == 0x0000ff. last_color = 0x0000ff.