Games of chance (card games, etc.) or wagers are not in themselves contrary to justice. They become morally unacceptable when they deprive someone of what is necessary to provide for his needs and those of others. The passion for gambling risks becoming an enslavement. Unfair wagers and cheating at games constitute grave matter, unless the damage inflicted is so slight that the one who suffers it cannot reasonably consider it significant. (#2413)
Under the entry "Lotteries" the Catholic Encyclopedia has this to say:
Morally it is objectionable if carried to excess as it tends to develop the gambling spirit and distract people from earning a livelihood by honest work. However, if there is no fraud of any sort in the transaction, and if there is some sort of proportion between the price of a ticket and the value of a chance of gaining a prize, a lottery cannot be condemned as in itself immoral.
A person may only engage in these activities with a strict adherence to virtue. First, he must act with temperance, whereby he keeps his passions and emotions under the control of reason, acts with moderation and uses material goods in a good way and in accord with the circumstances of his life.
Second, the virtue of justice governs both the game itself as well as the person playing the game. The game must be fair and all players must have an equal chance of winning. In justice, the player' s gambling must not prevent him from meeting his obligations to support himself or his families, pay his debts or fulfill other responsibilities.
For an in-depth discussion with regard to the common good, please read the article below.