Porting games can be a painful process. You essentially need to rewrite large parts of the game, mainly the rendering and the input part, as they completely depend on the platform. Depending on the platforms you may be able to keep some of your code, but it's not guaranteed. You may end up deleting the complete rendering part of your code and start from scratch.
The actual game-logic code can be reused, as it should be platform independend. To simplify porting to other platforms I would encourage you to cleanly separate logic code from rendering code to make porting easier.
If you are using a pre-made game engine you may be lucky and it already supports multiple platforms, reducing the needed effort to port your game significantly.
There is no other way than rewriting the incompatible parts.
Also take a look at this: Cross-platform independent developmentCross-platform independent development