There are three areas that you must take care of:
Even if you break something, you might get away with it. The company legal department can contact you and ask you nicely to remove the infringement. Or they can directly sue you, especially when the company is making profit by holding and licensing patents.
Every piece of art, source code or documentation is copyrighted by the author or the game studio. By using the original art you not necessarily breaking the copyright. Copyright gives the author exclusive right to allow or disallow anyone else to use the art. In case of commercial games, read the EULA to prevent any infringement. It is safe to assume that you can't use any original media files, but you can contact the authors - they might be willing to make an exception.
Copyright protects artwork, patents protect ideas. Even a simple idea like how to treat game achievments on consoles can be (and IS!) patented. You can read about some of the well known game patents here. You can never be sure that you are breaking some patent unless you know all of them. You need a legal department to make sure you are not, it's not an easy job. If there is any patent infringement, the patent holder will most likely contact you and ask you to either license their patent or remove it from your software. I have seen this happen several times, but not in a game. In case you dispute their right, they will most likely sue you. However as stated above, some companies make money by sueing other companies over patent infringement, so they might not even issue a warning.
Trademarks protect brands and names. You can't use identical or confusingly similar name to the trademarked one. Trademarks are usually limited to one industry, unless the trademark holder broadens (read: pays more) the trademark. E.g. you might be ok with your McDonald's shoe repair, but not with McDoland's fast-food.
But even if you really take care of all this, you might run into problems. Depends on how much revenue you are making and how much revenue is the other company losing. As an example, look at the image below. It is from one of the big lawsuits recently, EA vs. Zynga. No original artwork was used, no patents and no trademarks infringements. They settled the suit without anyone winning.
See also: Wikipedia article Video Games Clone