Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement this in Scala: In a tournament of arms two knights fight each other to the death: //> kl mt2.Knight -mt2$$anonfunSmain$1$Knight$1le643faf //> k2 : mt2.Knight
Implement this in Scala:
In a tournament of arms two knights fight each other to the death: //> kl mt2.Knight -mt2$$anonfunSmain$1$Knight$1le643faf //> k2 : mt2.Knight mt2$$anonfunSmain$1$Knight$1@6e8dacdf val klnew Knight ("Drobot") val k2-new Knight("Bldimore") kl.strategy-Mace k2.strategy-new CompositeStrategy (List (Mace, Stab, Stab)) k1.attack (k2) 9 0 9 3 //> Drobot is attacking Baldimore //1 macing // Baldimore.health-90 //> Baldimore is attacking Drobot //I macing // stabbing // stabbing // Drobot.health-60 2 k2.attack (k1) The design of the tournament combines the Strategy and Composite design patterns Knight trait name: String health: Int 100 sategy ckStrategy 1 attack(opponent Knight) strategies attack(opponent: Knight) Singleton Stab Knight) attack(opponent: Knight attack(opponent: Knight) In a tournament of arms two knights fight each other to the death: //> kl mt2.Knight -mt2$$anonfunSmain$1$Knight$1le643faf //> k2 : mt2.Knight mt2$$anonfunSmain$1$Knight$1@6e8dacdf val klnew Knight ("Drobot") val k2-new Knight("Bldimore") kl.strategy-Mace k2.strategy-new CompositeStrategy (List (Mace, Stab, Stab)) k1.attack (k2) 9 0 9 3 //> Drobot is attacking Baldimore //1 macing // Baldimore.health-90 //> Baldimore is attacking Drobot //I macing // stabbing // stabbing // Drobot.health-60 2 k2.attack (k1) The design of the tournament combines the Strategy and Composite design patterns Knight trait name: String health: Int 100 sategy ckStrategy 1 attack(opponent Knight) strategies attack(opponent: Knight) Singleton Stab Knight) attack(opponent: Knight attack(opponent: Knight)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started