BTW: Don't go arround asking for code... people will most probably ignore you if you do. Why? Because it's like telling us: "I am too lazy to do the work myself, so I am asking you do to it in my place. But I'll be more than happy to copy/paste your code into mine." Even if this wasn't your goal, which I believe myself, that's what it looks like.
It's an unwritten rule that you don't simply ask for code. If you ask specific questions, proving that you have already put some thought and work into the subject yourself, people will gladly help.
So if you tell me how far you are into developping your game, and where your specific problems lie, I will gladly help you work out the mechanics behind this kind of game. You'll learn more this way, than simply copying code.
The best piece of code will teach you nothing, if you do not know what it is supposed to do and how it works.
I'll try to answer your questions the best I can.