Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. trait Monster {
  2. fn attack(&self);
  3. fn new() -> Self;
  4. }
  5.  
  6. struct IndustrialRaverMonkey {
  7. life: int,
  8. strength: int,
  9. charisma: int,
  10. weapon: int,
  11. }
  12.  
  13. struct DwarvenAngel {
  14. life: int,
  15. strength: int,
  16. charisma: int,
  17. weapon: int,
  18. } ...
  19. impl Monster for IndustrialRaverMonkey { ...
  20. impl Monster for DwarvenAngel { ...
  21.  
  22. trait Monster {
  23. fn attack(&self);
  24. }
  25.  
  26. struct Characteristics {
  27. life: int,
  28. strength: int,
  29. charisma: int,
  30. weapon: int,
  31. }
  32.  
  33. struct IndustrialRaverMonkey {
  34. characteristics: Characteristics
  35. }
  36.  
  37. struct DwarvenAngel {
  38. characteristics: Characteristics
  39. }
  40.  
  41. fn same_attack(c: Characteristics) {
  42. fail!("not implemented")
  43. }
  44.  
  45. impl Monster for IndustrialRaverMonkey {
  46. fn attack(&self) {
  47. same_attack(self.characteristics)
  48. }
  49. }
  50.  
  51. impl Monster for DwarvenAngel {
  52. fn attack(&self) {
  53. same_attack(self.characteristics)
  54. }
  55. }
  56.  
  57. trait Monster {
  58. fn attack(&self);
  59. }
  60.  
  61. struct Characteristics {
  62. life: int,
  63. strength: int,
  64. charisma: int,
  65. weapon: int,
  66. }
  67.  
  68. enum Monsters {
  69. IndustrialRaverMonkey(Characteristics),
  70. DwarvenAngel(Characteristics),
  71. }
  72.  
  73. fn same_attack(_: &Characteristics) {
  74. fail!("not implemented")
  75. }
  76.  
  77. impl Monster for Monsters {
  78. fn attack(&self) {
  79. match *self {
  80. IndustrialRaverMonkey(ref c) => same_attack(c),
  81. DwarvenAngel(ref c) => same_attack(c)
  82. }
  83. }
  84. }
  85.  
  86. trait Actor {
  87. fn attack(&self);
  88. }
  89.  
  90. enum MonsterId {
  91. IndustrialRaverMonkey,
  92. DwarvenAngel
  93. }
  94.  
  95. struct Monster {
  96. life: int,
  97. strength: int
  98. }
  99.  
  100. impl Monster {
  101. fn new(id: MonsterId) -> Monster {
  102. match id {
  103. IndustrialRaverMonkey =>
  104. Monster { life: 12, strength: 8 },
  105.  
  106. DwarvenAngel =>
  107. Monster { life: 18, strength: 12 }
  108. }
  109. }
  110. }
  111.  
  112.  
  113. impl Actor for Monster {
  114. fn attack(&self) {}
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement