-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java~
42 lines (33 loc) · 970 Bytes
/
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
import java.util.*;
public class Game {
private Region region;
private LinkedList<Player> players;
public Game() {
region = new Region("TEST_REGION.txt");
players = new LinkedList();
} //constructor
public void submitAction(GameAction action) {
int x = action.getPlayer().getX();
int y = action.getPlayer().getY();
if (action.getType() == GameActionType.MOVE_UP) {
y--;
} else if (action.getType() == GameActionType.MOVE_DOWN) {
y++;
} else if (action.getType() == GameActionType.MOVE_LEFT) {
x--;
} else if (action.getType() == GameActionType.MOVE_RIGHT) {
x++;
}
if (region.canMoveTo(x, y)) {
action.getPlayer().setPosition(x, y);
}
/* ** */for(Player p:players)
/* ** */System.out.println(p.getX()+" "+p.getY());
} //submitAction
public void addPlayer(Player _p) {
players.add(_p);
} //addPlayer
public void removePlayer(Player _p) {
players.remove(_p);
} //removePlayer
}