Please explain. Are you having problems writing the code or is the code you have written not doing what you want?
Where is "life" defined and how is its value updated?
Try debugging the code by...