Skip to content

Instantly share code, notes, and snippets.

@grimrose
Created August 2, 2013 14:52
Show Gist options
  • Save grimrose/6140475 to your computer and use it in GitHub Desktop.
Save grimrose/6140475 to your computer and use it in GitHub Desktop.
どっかで見たことがあるような、無いような
package tddbc
class Fighter {
Action attack(Command command) {
new Action(list: command.apply())
}
}
enum Skill {
斬る,
払う,
けさ斬り,
ためる,
マルチウェイ
}
class Command {
List<Skill> input
List<Skill> apply() {
if (input == [Skill.斬る, Skill.払う, Skill.けさ斬り, Skill.斬る]) return [Skill.マルチウェイ]
input
}
}
class Action {
List<Skill> list
Damage getDamage() {
if (list.contains(Skill.マルチウェイ)) {
return new Damage(value: 65535)
}
new Damage(value: list.size() * 2)
}
}
class Damage {
Integer value
}
def fighter = new Fighter()
assert fighter.attack(new Command(input: [])).damage.value == 0
assert fighter.attack(new Command(input: [Skill.斬る])).list == [Skill.斬る]
def multiWayCommand = new Command(input: [Skill.斬る, Skill.払う, Skill.けさ斬り, Skill.斬る])
assert fighter.attack(multiWayCommand).list == [Skill.マルチウェイ]
assert fighter.attack(multiWayCommand).damage.value == 65535
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment