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:
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
The State Design Pattern can be used, for example, to manage the state of a tank in the StarCraft game. The pattern cons
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am