Morality in video games is a popular mechanic to allow for player choice in gameplay, giving the player greater input into how the story unfolds than traditional "on rails" plotting where the player simply follows the predetermined path the developers create. Allowing the player to choose, for example, how they solve a problem or overcome an obstacle both draws players into the game for the feeling that they can make meaningful decisions, but also serves to increase potential replay value - a player can replay a section or entire game and see what happens when they make the "other" choice.
These types of decisions are frequently, but not exclusively, found in the visual novel and role-playing genres. They have become more popular in many different genres of games, from RPG's to shooters, as they are a popular method of generating player involvement and immersion, as well as allowing for greater "role-playing" or decision-making, as one can choose to react to the game's choices based on either their own or a created set of moral rules and then seeing how the game's story continues. A more recent variation is the timed decisions mechanic.
There are two broad types of morality systems typically found in games, 'simple' and 'complex.'
Simple morality systems include those in games such as Fable or Knights of the Old Republic and consist of one-dimensional, clearly defined "good" and "evil" choices which are usually directly at odds with one another. These simple systems have the problem of rewarding a player if they consistently choose one or the other side, but not rewarding a nuanced playthrough where one may choose to be "good" in some circumstances and "evil" in others based on context. They have the advantage of being easy to implement and thus less demanding on the developer, as well as making it easy for players to know which choice they want to make based on their personal preferences.
More complex morality systems attempt, with varying degress of success, to make choices less about "good" and "evil" and more about two or more distinct but equally viable methods to solve a problem - the player will still solve the problem, but how they go about it is up to them. Games such as Mass Effect and Mass Effect 2 attempt to solve the problems of prior games by having two discrete meters, for "Paragon" and "Renegade" actions in Mass Effect's case. Although still loosely good/evil choosing to make a Paragon action does not directly penalize you if you make predominately Renegade options and vice versa, and thus allows for the player to put more thought into their actions instead of being rewarded for consistently choosing one or the other. Another complex morality system is used by the Shin Megami Tensei series, where choices are based on a three-way alignment system: Order, Neutral, and Chaos. Neither path is shown to be "good" or "evil", but each path is presented as having its own positive and negative traits. An even more complex morality system can be found in games such as Tactics Ogre, Way of the Samurai, Grand Theft Auto IV, and particularly visual novels such as Fate/Stay Night, School Days, 428: In a Blockaded Shibuya, and Zero Escape; titles like these offer moral choices that often have no right or wrong answer, some having significant consequences on the story without telegraphing to the player what those consequences may be as in a simple morality system.
On the other hand, these types of complex morality systems tend to require more development resources (unless it's a low-budget visual novel) and can, if not done carefully, lead to players making a choice they didn't "mean" to make, potentially causing a frustrating restart and having to replay and make a different choice. Some games attempt to resolve this issue by allowing players to fast-forward through parts they've already seen (as in, for example, the Zero Escape series) and/or navigate a timeline map showing the different narrative branches they've been through (as in, for example, Yu-No, Radiant Historia, Tactics Ogre, Final Fantasy XIII-2, and Zero Escape).
Regardless of method, morality choices are often at odds with scripted gameplay sequences and design, putting pressure on developers to write and script multiple pathways to the same end objective, or sometimes various different end objectives. Although the balancing act is difficult, it can lead to greatly rewarding gameplay and a richer game experience for the player.