The answer is Yes if the circumstances are right. First you need to determine the answers to several questions.
1. When is the foreclosure date on the house?
2. Do you plan to purchase the home to live in or to keep as an investment property?
3. Have you determined a purchase price? If so is it for what they owe on the property?
4. Will you be purchasing with cash or a loan?
5. Are there any deed restrictions on the property?
6. Does the property have any additional liens?
7. Do you plan to resell the property to your roommate?
There are a variety of options in this situation these are just a few questions to get you started to see if it is possible. Once you have answered these questions then we can really narrow down your options to see what is the best fit for you.