这个帖子是这个帖子的后续。
我正在将一个简单的战斗系统实现为玩具项目,这是您可以在《最终幻想》等游戏中找到的典型系统。我已经用类类型 + 自定义实例解决了臭名昭著的“命名空间污染”问题。例如:
type HitPoints = Integer
type ManaPoints = Integer
data Status = Sleep | Poison | .. --Omitted
data Element = Fire | ... --Omitted
class Targetable a where
name :: a -> String
level :: a -> Int
hp :: a -> HitPoints
mp :: a -> ManaPoints
status :: a -> Maybe [Status]
data Monster = Monster{monsterName :: String,
monsterLevel :: Int,
monsterHp :: HitPoints,
monsterMp :: ManaPoints,
monsterElemType :: Maybe Element,
monsterStatus :: …Run Code Online (Sandbox Code Playgroud)