Example #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);
 }
Example #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;
   }
 }
Example #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);
 }
Example #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();
 }
Example #5
0
 private int countFreeGuards() {
   int cnt = 0;
   for (Stone s : world.getStones()) {
     if (s.isFreeGuard()) {
       cnt++;
     }
   }
   return cnt;
 }
Example #6
0
 private void updateSweep() {
   if (currentStone == null) {
     return;
   }
   double sweep = ui.getSelectedSweep();
   if (sweep != currentStone.getSweep()) {
     currentStone.setSweep(sweep);
     game.sendAllStones(world.getStones());
   }
 }
Example #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();
 }
Example #8
0
 public void stonesUpdated(List<Stone> stones) {
   world.replaceStones(stones);
 }
Example #9
0
 public void stoneAdded(Stone stone) {
   world.addStone(stone);
 }
Example #10
0
 public void broomMoved(double x, double y) {
   world.setBroomLocation(x, y);
   game.sendBroom(x, y);
 }
Example #11
0
 int getBestTeam() {
   return world.getBestTeam();
 }
Example #12
0
 int getPoints() {
   return world.getPoints();
 }
Example #13
0
 void prepareForNewEnd() {
   world.clearStones();
 }