Esempio 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);
 }
Esempio 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;
   }
 }
Esempio 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);
 }
Esempio 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();
 }
Esempio n. 5
0
 private int countFreeGuards() {
   int cnt = 0;
   for (Stone s : world.getStones()) {
     if (s.isFreeGuard()) {
       cnt++;
     }
   }
   return cnt;
 }
Esempio 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());
   }
 }
Esempio 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();
 }
Esempio n. 8
0
 public void stonesUpdated(List<Stone> stones) {
   world.replaceStones(stones);
 }
Esempio n. 9
0
 public void stoneAdded(Stone stone) {
   world.addStone(stone);
 }
Esempio n. 10
0
 public void broomMoved(double x, double y) {
   world.setBroomLocation(x, y);
   game.sendBroom(x, y);
 }
Esempio n. 11
0
 int getBestTeam() {
   return world.getBestTeam();
 }
Esempio n. 12
0
 int getPoints() {
   return world.getPoints();
 }
Esempio n. 13
0
 void prepareForNewEnd() {
   world.clearStones();
 }