Пример #1
0
 // @Override
 public synchronized void sacarIdPlayer(String ids) {
   for (Player d : getJugadores()) {
     if (d.getId() != null) {
       if (d.getId().equals(ids)) {
         d.setId(null);
         break;
       }
     }
   }
 }
Пример #2
0
 private Player getPlayerId(String wd) {
   for (Player y : getJugadores()) {
     if (y.getId() != null) {
       if (y.getId().equals(wd)) {
         return y;
       }
     }
   }
   return null;
 }
Пример #3
0
 // @Override
 public synchronized void asignarIdPlayer(String ids) throws Exception {
   boolean found = false;
   for (Player d : getJugadores()) {
     if (d.getId() == null) {
       d.setId(ids);
       found = true;
       break;
     }
   }
   if (!found) {
     throw new Exception("Partida completa.");
   }
 }
Пример #4
0
 // @Override
 public synchronized void tick() {
   ArrayList<Element> d = new ArrayList<>();
   for (Player l : jugadores) {
     l.tick();
   }
   for (Player z : jugadores) {
     for (Element x : restriccion) {
       // To avoid player go outside the arena.
       tickUp(z, x, d);
       tickDown(z, x, d);
       tickRight(z, x, d);
       tickLeft(z, x, d);
     }
   }
   restriccion.removeAll(d);
 }
Пример #5
0
  // @Override
  public void movimientoJugadores(String pl, int sel, int esp) {
    Player fi = getPlayerId(pl);
    switch (sel) {
      case KeyEvent.VK_RIGHT: // 39:
        fi.setVelX(esp); // Flecha derecha
        break;

      case KeyEvent.VK_LEFT: // 37:
        fi.setVelX(-esp); // Flecha izquierda
        break;

      case KeyEvent.VK_UP: // 38:
        fi.setVelY(-esp); // Flecha arriba
        break;

      case KeyEvent.VK_DOWN: // 40:
        fi.setVelY(esp); // Flecha abajo
        break;
    }
  }
Пример #6
0
 private void tickDown(Player z, Element x, ArrayList<Element> d) {
   if ((z.getY() - (x.getY() - 15)) > 0
       && (z.getY() - (x.getY() - 15)) < 15
       && (z.getX() - x.getX()) < 10
       && (z.getX() - x.getX()) > -5) {
     if (z.getCol().equals(x.getCol())) {
       d.add(x);
     } else if (x.getCol().equals(BLUE)) {
       if (meta.equals(NO)) {
         meta = WINNERS;
       } else {
         d.add(x);
       }
     } else {
       z.setY(z.getY() - (z.getY() - (x.getY() - 15)));
     }
   }
 }