Hello Viral,
Thank you for your question. These tenses are difficult to get right every time because of the differences between British and American English. Let me answer according to strict British English rules. These will help you in your own usage, but do not be surprised if you hear 'ungrammatical' usage in movies and informal conversations.
Your four answers to the question 'What have you done today?' are all possible, but let me add some notes:
1) I have played tennis. ( ... and I've done X, and I've done Y) - This is the best answer: telling them the different things you have done.
2) I have played tennis for 2 hours. - Correct grammatically, but again, you should mention the other things you've done. If you only want to talk about playing tennis, then it's best to put it in a past time frame: I went to the club at 9 o'clock and played tennis with Jim for two hours.
3) I had played tennis for 2 hours before friend A visited me. - See 4) using the Past Perfect instead of Perfect Continuous is acceptable here.
4) I had been playing tennis for 2 hours before friend A visited me. - As with 2), if you want to be detailed, introduce a time frame: Friend A visited me at 11. I had been playing ......
To answer your other question:
While it is o.k. to replace Past Perfect Continuous with Past Perfect (because native speakers tend to do it in daily usage), it is not o.k. to replace Present Perfect Continuous with 'for' and 'since' with Present Perfect when talking about short-term actions. So, avoid saying 'It has rained for two hours / since 9 a.m. Say: 'It has been raining for two hours / since 9 a.m.
I hope this answers your question.