Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
ClientMicropolis.java
Go to the documentation of this file.
1 package micropolisj.network;
2 
3 import java.rmi.RemoteException;
4 
5 import micropolisj.engine.MapState;
6 import micropolisj.engine.Micropolis;
7 import micropolisj.engine.PlayerInfo;
8 import micropolisj.engine.Sprite;
9 import micropolisj.engine.ToolStroke;
10 
11 public class ClientMicropolis extends Micropolis{
12 
14 
15  public ClientMicropolis(String IP) throws RemoteException {
16  super();
17  remote = new RemoteClient(IP);
18  }
19 
20  @Override
21  public void animate() {
22  MapInfo info = remote.getMap();
24  applyPlayerInfo(playerInfo);
25  applyMapInfo(info);
26  super.animate();
27  animateTiles();
28  moveObjects();
29 // TODO: take census every so many steps
30 // takeCensus();
31 // takeCensus2();
32  fireEvents();
33  }
34 
35  private void applyMapInfo(MapInfo info) {
36  if(info != null) {
37 // map = info.map;
38  for(int x = 0; x < info.map.length; x++) {
39  for(int y = 0; y < info.map[0].length; y++) {
40  if(map[x][y] != info.map[x][y]) {
41  map[x][y] = info.map[x][y];
42 // System.out.println(x + ", " + y);
43  fireTileChanged(y, x);
44  }
45  }
46  }
47  sprites = info.sprites;
48  for(Sprite sprite : sprites) {
49  sprite.setMicropolis(this);
50  }
51  this.cityTime = info.cityTime;
52 // playerInfo.budget.setValues(info.cityBudget);
53 // fireFundsChanged();
54  }
55  }
56 
57  private void fireEvents() {
62 // fireMapOverlayDataChanged(MapState.ALL);
63 
64  }
65 
66 
68  this.playerInfo = playerInfo;
69  this.playerInfo.evaluation.setEngine(this);
70  }
71 
72  public void toolUsed(ToolStroke tool) {
73  PlayerInput input = new PlayerInput(tool);
74  remote.sendInput(input);
75  }
76 
77  @Override
78  public void setBudgetNumbers(int newTaxRate, double roadPct, double newRoadPct, double newPolicePct, double newFirePct, double newResearchPct) {
79  super.setBudgetNumbers(newTaxRate, roadPct, newRoadPct, newPolicePct, newFirePct, newResearchPct);
80  PlayerInput budgetInput = new PlayerInput(null);
81  budgetInput.setBudgetNumbers(newTaxRate, roadPct, newPolicePct, newFirePct, newResearchPct);
82  remote.sendInput(budgetInput);
83  }
84 
85  @Override
86  public int getPlayerID() {
87  return remote.getID();
88  }
89 
90  public String getPlayerIP() {
91  return remote.getIP();
92  }
93 
94  @Override
95  public PlayerInfo getPlayerInfo(int playerID) {
96  return playerInfo;
97  }
98 }