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