-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java
72 lines (63 loc) · 2.22 KB
/
Game.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
62
63
64
65
66
67
68
69
70
71
package Game_Tank_multiplayer;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Game extends Application {
static Pane pane;
private Map map;
private Player player;
public Game(Map map){
this.map = map;
}
public Game() {
}
public void setMap(Map map) {
this.map = map;
}
public void addPlayer(Player player) {
this.player = player;
}
public void start(Stage stage) throws FileNotFoundException {
init();
Scene scene = new Scene(map, 560, 560);
Tank tank = new Tank(map.getStartPosition().getX(), map.getStartPosition().getY(),map);
map.getChildren().add(tank.getTank());
map.getChildren().addAll(map.getTrees());
scene.setOnKeyPressed(e -> {
if(e.getCode() == KeyCode.UP)
tank.moveUp();
if(e.getCode() == KeyCode.DOWN)
tank.moveDown();
if(e.getCode() == KeyCode.RIGHT)
tank.moveRight();
if(e.getCode() == KeyCode.LEFT)
tank.moveLeft();
if(e.getCode() == KeyCode.SPACE){
Bullet bullet = new Bullet(map, tank);
map.getChildren().remove(tank.getTank());
map.getChildren().removeAll(map.getTrees());
map.getChildren().addAll(bullet.getBullet(), tank.getTank());
map.getChildren().addAll(map.getTrees());
}
});
stage.setScene(scene);
stage.setTitle("Tank");
stage.show();
}
public void init() throws FileNotFoundException {
// Scanner input = new Scanner(System.in);
// System.out.print("Enter a file name: ");
// String fileName = input.next();
// File file = new File(fileName);
// if(!file.exists())
// throw new InvalidMapException("Given file does not exist");
// System.out.print("Enter a size of map: ");
// int size = input.nextInt();
map = new Map(new Scanner(new File("map1.txt")), 14);
}
}