Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Monster {
- fn attack(&self);
- fn new() -> Self;
- }
- struct IndustrialRaverMonkey {
- life: int,
- strength: int,
- charisma: int,
- weapon: int,
- }
- struct DwarvenAngel {
- life: int,
- strength: int,
- charisma: int,
- weapon: int,
- } ...
- impl Monster for IndustrialRaverMonkey { ...
- impl Monster for DwarvenAngel { ...
- trait Monster {
- fn attack(&self);
- }
- struct Characteristics {
- life: int,
- strength: int,
- charisma: int,
- weapon: int,
- }
- struct IndustrialRaverMonkey {
- characteristics: Characteristics
- }
- struct DwarvenAngel {
- characteristics: Characteristics
- }
- fn same_attack(c: Characteristics) {
- fail!("not implemented")
- }
- impl Monster for IndustrialRaverMonkey {
- fn attack(&self) {
- same_attack(self.characteristics)
- }
- }
- impl Monster for DwarvenAngel {
- fn attack(&self) {
- same_attack(self.characteristics)
- }
- }
- trait Monster {
- fn attack(&self);
- }
- struct Characteristics {
- life: int,
- strength: int,
- charisma: int,
- weapon: int,
- }
- enum Monsters {
- IndustrialRaverMonkey(Characteristics),
- DwarvenAngel(Characteristics),
- }
- fn same_attack(_: &Characteristics) {
- fail!("not implemented")
- }
- impl Monster for Monsters {
- fn attack(&self) {
- match *self {
- IndustrialRaverMonkey(ref c) => same_attack(c),
- DwarvenAngel(ref c) => same_attack(c)
- }
- }
- }
- trait Actor {
- fn attack(&self);
- }
- enum MonsterId {
- IndustrialRaverMonkey,
- DwarvenAngel
- }
- struct Monster {
- life: int,
- strength: int
- }
- impl Monster {
- fn new(id: MonsterId) -> Monster {
- match id {
- IndustrialRaverMonkey =>
- Monster { life: 12, strength: 8 },
- DwarvenAngel =>
- Monster { life: 18, strength: 12 }
- }
- }
- }
- impl Actor for Monster {
- fn attack(&self) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement