In "Sharing" Pref Pane, Firewall tab, New> select "Other" from pulldown, enter the TCP and UDP port number(s) specified for the app, Enter app name in the "Description" field. Make sure in the list that the app's "Allow" checkbox is ticked.
If you're using a router, you may also have to also open or forward ports.
Somewhere in the documenttation or troubleshooting guide (printed or online) for the game or whatever program, will be info on what TCP and/or UDP ports need to be open. The software maker's site or user forums related to it might be helpful.