Objective
In the above, I have described how to test, how to refactor tests, and through experiments to master the technology of map display. This article will use the technology shown in the map to show the bomber, and let our bomber move.
Note: In order to improve the quality of the blog and focus on recording development and iterative thinking practices, this article and subsequent posts will no longer record the test process.
The purpose of this article
To realize the bomber's display and movement.
Review the updated domain model above
Thinking about the domain model
The Showmap class is responsible for displaying the map, including the game logic. The game category is responsible for the logic of the game, so showmap and game have duplication of responsibilities. Moreover, the logic of the display map is not very complicated, and it can be directly placed in the game without the need for a special class to take charge of this part of the logic.
Now come back and look at the display map implementation of the Showmap class:
Drawmap:function () {
var i = 0,
j = 0,
map = Bomberconfig.map,
bitmap = null,
mapData = Mapdataopera Te.getmapdata (),
x = 0,
y = 0,
img = null;
This._createlayer ();
for (i = 0; i < map. ROW; i++) {
//Note!
//y is longitudinal height,x for transverse width
y = i * map. HEIGHT;
for (j = 0; J < map. COL; J + +) {
x = J * Map. WIDTH;
img = this._getmapimg (i, J, MapData);
Bitmap = Bitmapfactory.createbitmap ({img:img, width:map. WIDTH, Height:map. HEIGHT, x:x, y:y});
This.layer.appendChild (bitmap);
}
This.layer.draw ();
}
Showmap will display the specific implementation of the map delegated to layer, responsible for the operation of layer, this responsibility can also be moved to game. And given that the Showmap class is used as an experiment (see development strategy above), now the "show map" function has been implemented, SHOWMAP is not necessary.
So, I remove the Showmap class and move it into game.
The domain model after reconstruction