Exemplo n.º 1
0
 void prepareFreeGuardZone(int team) {
   List<Stone> stones = world.getStones();
   savedStones = new ArrayList<Stone>(stones.size());
   for (Stone s : stones) {
     savedStones.add(s.clone());
   }
   logger.fine("Saved stones: " + savedStones);
   logger.info("Marking free guards");
   world.markFreeGuards(team);
 }
Exemplo n.º 2
0
 public void step(double dt) {
   updateSweep();
   int freeGuards = countFreeGuards();
   boolean moving = world.step(dt);
   if (countFreeGuards() < freeGuards) {
     logger.info("Free guard removed, resetting stones with: " + savedStones);
     world.replaceStones(savedStones);
   }
   if (!moving && live) {
     live = false;
     allStopped();
   } else if (moving && !live) {
     live = true;
   }
 }
Exemplo n.º 3
0
 WorldController(Game game, UIProvider ui) {
   this.game = game;
   this.ui = ui;
   world = new World();
   world.setBroomLocation(0, CurlingConstants.TEE_TO_CENTER);
   ui.setWorld(world);
 }
Exemplo n.º 4
0
 private void allStopped() {
   logger.info("All stones have stopped moving");
   currentStone = null;
   for (Stone s : world.getStones()) {
     s.setFreeGuard(false);
   }
   game.getMatchCtrl().nextTurn();
 }
Exemplo n.º 5
0
 private int countFreeGuards() {
   int cnt = 0;
   for (Stone s : world.getStones()) {
     if (s.isFreeGuard()) {
       cnt++;
     }
   }
   return cnt;
 }
Exemplo n.º 6
0
 private void updateSweep() {
   if (currentStone == null) {
     return;
   }
   double sweep = ui.getSelectedSweep();
   if (sweep != currentStone.getSweep()) {
     currentStone.setSweep(sweep);
     game.sendAllStones(world.getStones());
   }
 }
Exemplo n.º 7
0
 public void throwStone() {
   double speed = ui.getSpeed();
   speed = Math.pow(speed, 1.5);
   double v = (1.0 - speed) * 2.3 + 3.0 * speed;
   Vect2d broom = new Vect2d(world.getBroomX(), world.getBroomY());
   Vect2d dir = broom.minus(CurlingConstants.STONE_START).normalized();
   Vect2d vel = dir.times(v);
   double da = 1.0;
   if (!ui.isHandRight()) {
     da = -da;
   }
   currentStone =
       new Stone(CurlingConstants.STONE_START, vel, 0, da, game.getMatchCtrl().getCurrentTeam());
   double sweep = ui.getSelectedSweep();
   currentStone.setSweep(sweep);
   logger.info("New stone: " + currentStone);
   world.addStone(currentStone);
   game.sendNewStone(currentStone);
   ui.endTurn();
 }
Exemplo n.º 8
0
 public void stonesUpdated(List<Stone> stones) {
   world.replaceStones(stones);
 }
Exemplo n.º 9
0
 public void stoneAdded(Stone stone) {
   world.addStone(stone);
 }
Exemplo n.º 10
0
 public void broomMoved(double x, double y) {
   world.setBroomLocation(x, y);
   game.sendBroom(x, y);
 }
Exemplo n.º 11
0
 int getBestTeam() {
   return world.getBestTeam();
 }
Exemplo n.º 12
0
 int getPoints() {
   return world.getPoints();
 }
Exemplo n.º 13
0
 void prepareForNewEnd() {
   world.clearStones();
 }