@Override
  public int onPlayerLeaveRaceCheckpoint(int playerId) {
    try {
      IPlayer player = sampObjectPool.getPlayer(playerId);

      if (player instanceof Player) {
        RaceCheckpointLeaveEvent event = new RaceCheckpointLeaveEvent(player);
        eventManager.dispatchEvent(event, player.getRaceCheckpoint(), player);
      }

      return 1;
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }
  }
Example #2
0
  public static CharSequence dumpScoreCard(IScoreCard scoreCard) {
    // Headers
    List<String> headers = new ArrayList<String>();
    headers.add("");
    for (IPlayer player : scoreCard.getPlayers()) {
      headers.add(player.getName());
    }

    // Data
    final List<List<String>> data = new ArrayList<List<String>>();
    traverseScore(
        scoreCard,
        new IScoreVisitor() {
          public void visit(IScore score) {
            if (score instanceof ITurnScore) {
              ITurnScore turnScore = (ITurnScore) score;
              List<String> row = new ArrayList<String>();

              String scoreName = turnScore.getClass().getSimpleName();
              if (turnScore instanceof SumScore) {
                SumScore sumScore = (SumScore) turnScore;
                scoreName += " " + sumScore.getValue();
              }
              row.add(scoreName);

              for (IPlayer player : turnScore.getPlayers()) {
                row.add("" + turnScore.getScore(player));
              }

              data.add(row);
            } else if (score instanceof IScoreGroup) {
              IScoreGroup scoreGroup = (IScoreGroup) score;

              List<String> row = new ArrayList<String>();

              row.add("Total");
              for (IPlayer player : scoreGroup.getPlayers()) {
                row.add("" + scoreGroup.getScore(player));
              }

              data.add(row);
            }
          }
        });

    return dumpTable(headers, data);
  }
Example #3
0
 public void showWord(String word, java.util.List<BoardCell> letterLocations, IPlayer player) {
   myWordList.add(word);
   scoreText.setText(player.getScore() + "");
   scoreText.paintImmediately(scoreText.getVisibleRect());
   myWordList.paintImmediately(myWordList.getVisibleRect());
   // myBoardPanel.highlightDice(letterLocations);
   wordEntryField.clear(); // clear the wordEntryField text
 }
Example #4
0
  public void step() {
    if (hasPuck()) // If we have the puck.
    skate(2600, 0, 1000); // Skate towards the goal.
    else if (Util.dist(
            getX() - getPuck().getX(), // If the puck is within 5m.
            getY() - getPuck().getY())
        < 500) skate(getPuck(), 1000); // Get puck
    else {
      IPlayer best = null;
      for (int i = 0; i < 12; ++i) { // Loop through all players.
        IPlayer cur = getPlayer(i);

        if (cur.isOpponent()
            && // If player is opponent...
            (best == null
                || Util.dist(
                        getX() - cur.getX(), // ...and closest so far...
                        getY() - cur.getY())
                    < Util.dist(getX() - best.getX(), getY() - best.getY())))
          best = cur; // ...save player.
      }

      skate(best, 1000); // Tackle closest opponent.
    }
  }
Example #5
0
  public void setGame(IGame game) {
    if (this.game != null) {
      this.game.removeGameListener(gameListener);
    }
    this.game = game;
    if (game != null) {
      game.addGameListener(gameListener);

      StringBuffer b = new StringBuffer();
      IPlayer[] players = game.getPlayers();
      for (int i = 0; i < players.length; i++) {
        IPlayer player = players[i];
        if (i > 0) b.append(" vs ");
        b.append(player.getName());
      }
      final String title = b.toString();

      // TODO unnecessary thread sync?
      exec(
          new Runnable() {
            public void run() {
              setPartName(title);
            };
          });
    }
    updateTileRack();

    MoveListView moveListView = (MoveListView) getSite().getPage().findView(MoveListView.ID);
    if (moveListView != null) {
      moveListView.setGame(game);
    }

    TilePoolView tilePoolView = (TilePoolView) getSite().getPage().findView(TilePoolView.ID);
    if (tilePoolView != null) {
      tilePoolView.setGame(game);
    }

    AnalysisView analysisView = (AnalysisView) getSite().getPage().findView(AnalysisView.ID);
    if (analysisView != null) {
      analysisView.setGame(game);
    }
  }
Example #6
0
  /**
   * if haskey == true, enterDoor will cause endround, so the game can continue to the next round or
   * go to the victory screen. Otherwise, this method won't cause anything.
   *
   * @param game
   * @throws java.lang.InterruptedException
   * @throws java.io.IOException
   */
  public void enterDoor(Game game) throws InterruptedException, IOException {
    // First check if this entering was on the last floor (last level).
    if (game.getFloorAmount() == game.getCurrentFloor()) {
      boolean humanFound = false;

      while (!humanFound) {
        for (IPlayer player : game.getPlayers()) {
          try {
            if (player.getCharacter() instanceof Human) {
              game.endGame();
              humanFound = true;
            }
          } catch (RemoteException ex) {
            Logger.getLogger(Human.class.getName()).log(Level.SEVERE, null, ex);
          }
        }
      }
    } else {
      game.setRoundEnded(true);
    }
  }
  @Override
  public int onPlayerText(int playerId, String text) {
    try {
      IPlayer player = sampObjectPool.getPlayer(playerId);

      if (player instanceof Player) {
        PlayerTextEvent event = new PlayerTextEvent(player, text);
        eventManager.dispatchEvent(event, player);

        if (event.getResult() != 0) {
          Player.sendMessageToAll(Color.WHITE, "{FE8B13}" + player.getName() + ": {FFFFFF}" + text);
          return 1;
        }
      }

      return 0;
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }
  }
  @Override
  public int onPlayerExitedMenu(int playerId) {
    try {
      IPlayer player = sampObjectPool.getPlayer(playerId);
      IMenu menu = player.getMenu();

      MenuExitedEvent event = new MenuExitedEvent(menu, player);

      if (player instanceof Player && menu instanceof Menu) {
        eventManager.dispatchEvent(event, menu, player);
      } else if (player instanceof Player) {
        eventManager.dispatchEvent(event, player);
      } else if (menu instanceof Menu) {
        eventManager.dispatchEvent(event, menu);
      }

      return 1;
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }
  }
Example #9
0
 private void initPlayers(IAutoPlayer compPlayer) {
   computerPlayer = compPlayer;
   computerPlayer.setView(computerArea);
   humanPlayer = new HumanPlayer("Human");
   humanPlayer.setView(humanArea);
 }
Example #10
0
  // Intelligence of goalie.
  public void step() {
    IPuck puck = getPuck();
    if (hasPuck()) {
      shoot(getPlayer(1), 200);
      return;
    }

    if (puck.getSpeed() > 60 && puck.getX() > -2600) {
      double angle = puck.getHeading();
      if (angle < 0) angle += 360;
      double theLastAngle = lastAngle;
      lastAngle = angle;
      if (theLastAngle > -1000) angle = (angle + theLastAngle) / 2; // smoothing
      if (angle > 95 && angle < 265) {
        angle *= 3.14159 / 180.0;
        double dx = -Math.cos(angle), dy = Math.sin(angle);
        double Dx = puck.getX() - (-2600), Dy = puck.getY();
        dy *= Dx / dx;
        dy += puck.getY();
        if (-120 < dy && dy < 120) {
          // will hit dy! shit
          // setMessage("shit shit shit " + puck.getHeading() + " " + String.format("%.2f", dy));
          int speed;
          dy = Util.clampAbs(dy, 100);
          if (puck.isHeld()) {
            speed = 20;
          } else {
            double timeToGoal = (Dx - 80) / (dx * puck.getSpeed());
            dbgStr += String.format(" | %.0f -> %.0f t = %.1f, ", (double) getY(), dy, timeToGoal);
            if (timeToGoal <= 0) {
              speed = MAX_GLIDE;
            } else {
              double wantedSpeed = (dy - getY()) / (double) timeToGoal;
              int cur = getGlide();
              dbgStr += " gl " + String.format("%.0f %.0f ", (double) cur, wantedSpeed);
              int bestSpeed = 0;
              double bestDif = 100000;
              for (int sp = -440; sp <= 440; sp += 2) {
                double r = Math.abs(sp - cur) / (double) ACCELERATION / timeToGoal;
                // if (r > 1) continue;
                double res = (cur + sp) * r / 2 + sp * (1 - r);
                double d = Math.abs(res - wantedSpeed);
                if (d < bestDif) {
                  bestDif = d;
                  bestSpeed = sp;
                }
              }
              speed = Util.clampPos(Math.abs(bestSpeed), 444);
              dbgStr += " best " + speed;
            }
          }
          skate(GOAL_POSITION.getX() + 60, (int) dy, speed);
          turn(getPuck(), MAX_TURN_SPEED);
          return;
        }
        // else setMessage("puh position " + String.format("%.2f", dy));
      }
      // else setMessage("puh angle " + angle + dbgStr);
    }
    // else setMessage("puh speed " + puck.getSpeed() + dbgStr);
    lastAngle = -1000;

    // slow or wrong; keep it safe
    IPlayer holder = puck.getHolder();
    if (holder != null
        && holder.getX() - (-2600) > 0
        && Math.abs(holder.getY()) > Math.abs(holder.getX() - (-2600)) * 0.7) {
      // outside a cone - move to side
      skate(GOAL_POSITION.getX() + 40, Util.clampAbs(puck.getY(), 100), MAX_GLIDE);
      turn(puck, MAX_TURN_SPEED);
    } else { // if (Math.random() < 0.7) {
      // protect
      int y = Util.clampAbs(puck.isHeld() ? holder.getY() / 4 : 0, 100);
      skate(GOAL_POSITION.getX() + 60, y, 30);
      turn(0, MAX_TURN_SPEED);
    }
  }
Example #11
0
 private ITileRack getLocalTileRack() {
   IPlayer player = game.getLocalPlayer();
   if (player == null) return null;
   return player.getTileRack();
 }
Example #12
0
  private void drawPlayerStats(GC gc, Rectangle bounds, IPlayer player, int align) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    int p = w / 32;

    Color fillColor = null;
    Color handleColor = null;
    Color scoreColor = null;
    Color clockColor = null;

    if (game.getGameState() == GameState.ENDED) {
      if (player == game.getWinner()) {
        fillColor = new Color(null, 0, 164, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      } else {
        fillColor = new Color(null, 164, 0, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      }
    } else {
      if (player == game.getCurrentPlayer()) {
        fillColor = new Color(null, 0, 0, 192);
        handleColor = new Color(null, 205, 205, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 215, 215, 215);
      } else {
        fillColor = new Color(null, 153, 153, 153);
        handleColor = new Color(null, 0, 0, 128);
        scoreColor = new Color(null, 0, 0, 0);
        clockColor = new Color(null, 0, 0, 0);
      }
    }

    // fill
    gc.setBackground(fillColor);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);

    // draw handle
    int n = h / 4;
    Font font = new Font(null, "Arial", n, SWT.BOLD);
    String s = player.getName();
    gc.setFont(font);
    gc.setForeground(handleColor);
    Point extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y, true);
    }
    font.dispose();

    // save width
    int i = extent.x + p;

    // draw clock
    font = new Font(null, "Courier New", n, SWT.BOLD);
    s = player.getClock().toString();
    gc.setFont(font);
    gc.setForeground(clockColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y + h - extent.y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y + h - extent.y, true);
    }
    font.dispose();

    // draw score
    font = new Font(null, "Arial", h / 2, SWT.BOLD);
    s = Integer.toString(player.getScore());
    gc.setFont(font);
    gc.setForeground(scoreColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + i + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    } else {
      gc.drawString(s, x + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    }
    font.dispose();

    fillColor.dispose();
    handleColor.dispose();
    scoreColor.dispose();
    clockColor.dispose();
  }