
上QQ阅读APP看书,第一时间看更新
Time for action — changing the gameClasses file
The first thing you need to do is add a new object to the gameClasses.monkey
file.
- Open the
gameClasses.monkey
file. - Add an
Import
statement for thecityClass.monkey
file.Import mainClass Import cityClass
- Save the file and close it.
What just happened?
We have added an Import
statement for our new cityClass.monkey
file to the gameClasses.monkey
file. As we only import gameClasses.monkey
in all of our scripts, the new class will be automatically visible in them, and so will all the other objects we create later on too.
Modifying the RocketCommander class
Ok, now comes the actual fun part. First, we want to to create some cities in our game. For this, we have created the CreateCity
function. To set up the game objects at the beginning of a game, inside the RocketCommander
class, there is a method called SetupGame
. So, let's modify it.