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);
 }
 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;
   }
 }
 WorldController(Game game, UIProvider ui) {
   this.game = game;
   this.ui = ui;
   world = new World();
   world.setBroomLocation(0, CurlingConstants.TEE_TO_CENTER);
   ui.setWorld(world);
 }
 private void allStopped() {
   logger.info("All stones have stopped moving");
   currentStone = null;
   for (Stone s : world.getStones()) {
     s.setFreeGuard(false);
   }
   game.getMatchCtrl().nextTurn();
 }
 private int countFreeGuards() {
   int cnt = 0;
   for (Stone s : world.getStones()) {
     if (s.isFreeGuard()) {
       cnt++;
     }
   }
   return cnt;
 }
 private void updateSweep() {
   if (currentStone == null) {
     return;
   }
   double sweep = ui.getSelectedSweep();
   if (sweep != currentStone.getSweep()) {
     currentStone.setSweep(sweep);
     game.sendAllStones(world.getStones());
   }
 }
 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();
 }
 public void stonesUpdated(List<Stone> stones) {
   world.replaceStones(stones);
 }
 public void stoneAdded(Stone stone) {
   world.addStone(stone);
 }
Exemple #10
0
 public void broomMoved(double x, double y) {
   world.setBroomLocation(x, y);
   game.sendBroom(x, y);
 }
Exemple #11
0
 int getBestTeam() {
   return world.getBestTeam();
 }
Exemple #12
0
 int getPoints() {
   return world.getPoints();
 }
Exemple #13
0
 void prepareForNewEnd() {
   world.clearStones();
 }