Skip to content

Instantly share code, notes, and snippets.

@brianhsu
Created January 7, 2010 11:51
Show Gist options
  • Save brianhsu/271187 to your computer and use it in GitHub Desktop.
Save brianhsu/271187 to your computer and use it in GitHub Desktop.
/**
* 人物卡片擁有三個屬性:名稱、生命值、描述
*/
case class PersonCard (name: String, description: String, hp: Int) {
def hasHP (hp: Int) = PersonCard (name, description, hp)
def describeAs (description: String) = PersonCard (name, description, hp)
}
/**
* 每個遊戲裡有複數張人物卡片
*/
case class GameBoard (title: String, personCards: List[PersonCard]) {
def hasPersonCards (cards: PersonCard*) = GameBoard (title, cards.toList)
}
/**
* 神奇的轉型函式,DSL 的秘密就在這裡
*/
implicit def str2PersonCard (name: String) = PersonCard (name, "", 0)
implicit def str2GameBoard (title: String) = GameBoard (title, Nil)
/**
* 今天在 CWT23 買的 APH 同人遊戲裡的一些國家卡片
*/
"APH 紙上遊戲" hasPersonCards (
"台灣" hasHP 60 describeAs "一般來說,中國、香港、日本、韓國、台灣" +
"裡,台灣最好相處(因為太弱啦),雖然自" +
"己不覺得,但是大家都覺得她家的夜市很好" +
"玩。",
"香港" hasHP 70 describeAs "被英國領養了一段時間,最近回大哥家住," +
"有點適應不良,對金錢很精明,但人際關係" +
"則有點無力,看不大出來他在想什麼。",
"美國" hasHP 100 describeAs "熱血青年,自認是世界的警察,對於做家務" +
"有點懶洋洋,不過墨西哥會從後院的洞偷溜" +
"進來工作所以沒關係,是最近一次大流行感" +
"冒的病源"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment