-
Notifications
You must be signed in to change notification settings - Fork 3
/
MapGenerator.java
61 lines (55 loc) · 1.7 KB
/
MapGenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.danilchican.pacman;
import com.danilchican.pacman.Block.BlockType;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
/**
* The class wich generate masks for map
*
* @author Vlad Danilchik
*
*/
public class MapGenerator {
/**
* Generate map
*
* @param level number of level
* @see MapGenerator#generateMap(int)
*/
public static void generateMap(int level) {
// set background
Constants.gameRoot.setPrefSize(Constants.screenWidth, Constants.screenHeight);
Rectangle rect = new Rectangle(Constants.screenWidth, Constants.screenHeight);
rect.setFill(Color.BLACK);
// add rectangle to gameRoot
Constants.gameRoot.getChildren().addAll(rect);
// generate map blocks
for (int i = 0; i < LevelData.levels[level - 1].length; i++) {
String line = LevelData.levels[level - 1][i];
for (int j = 0; j < line.length(); j++) {
switch (line.charAt(j)) {
case '0':
new Block(BlockType.BRICK, Constants.MARGIN_LEFT_RIGHT + j * Constants.BlockWidth,
Constants.MARGIN_TOP + i * Constants.BlockHeight);
break;
case '1':
new Block(BlockType.FOOD, Constants.MARGIN_LEFT_RIGHT + j * Constants.BlockWidth,
Constants.MARGIN_TOP + i * Constants.BlockHeight);
break;
}
}
}
}
/**
* Clear game screen after win or lose
*
* @see MapGenerator#clearGameScene()
*/
public static void clearGameScene() {
Constants.main_scene.setRoot(Constants.mainRoot);
Constants.enemies.clear();
Constants.blocks.clear();
Constants.countFoodLevel = 0;
Constants.CurrentCountBonuses = 0;
Constants.keys.clear();
}
}