Exercises
In this section, you will help Steve to develop and refactor his tower defense game in a functional programming way.
Exercise 1
Name and count all expressions and all statements in the code snippet below:
Tower mainTower = new(position: new Vector2(5, 5)); for (int level = 1; level <= mainTower.MaxLevel; level++) { double upgradeCost = 100 * Math.Pow(1.5, level - 1); Console.WriteLine($"Upgrading to level {level} costs {upgradeCost} gold"); if (playerGold >= upgradeCost) { mainTower.Upgrade(); playerGold -= upgradeCost; } }
Exercise 2
Refactor the code below to use expressions instead...