The State Design Pattern can be used, for example, to manage the state of a tank in the StarCraft game. The pattern cons

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The State Design Pattern can be used, for example, to manage the state of a tank in the StarCraft game. The pattern cons

Post by answerhappygod »

The State Design Pattern can be used, for example, tomanage the state of a tank in the StarCraft game.
The pattern consists in isolating the state logic in differentclasses rather than having multiple ifs to determine whatshould happen.
Your Task
Complete the code so that when a Tank goesinto SiegeMode it cannot move and its damage goesto 20. When it goes to TankMode it should be able tomove and the damage should be set to 5.
You have 3 classes:
The State Design Pattern Can Be Used For Example To Manage The State Of A Tank In The Starcraft Game The Pattern Cons 1
The State Design Pattern Can Be Used For Example To Manage The State Of A Tank In The Starcraft Game The Pattern Cons 1 (70.69 KiB) Viewed 28 times
30 31 32 RESET... 10 } 11 12 class SiegeState: UnitState { 13 14 15 16 33 9 10 Solution Language: Kotlin Version: 1.3 17 } 18 19 20 21 22 23 24 25 26 class Tank: Unit { 27 28 29 val canMove: Boolean val damage: Int } } override val canMove: Boolean override val damage: Int //you code here class TankState: UnitState { override val canMove: Boolean override val damage: Int //you code here //you code here override var state: UnitState override val canMove: Boolean override val damage: Int Sample Tests (Modifiable) 1 import org.junit.Assert.* 2 import org.junit. Test 3 import kotlin.random. Random 4 5 class Challenge Tests { 6 @Test fun shouldChangeToTankState Properly() { val tank Tank() CHANGE
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply