Example #1
0
 /**
  * Generates the Knight's moveset by looping clockwise. First take two steps in a certain
  * direction to create a baseLocation, and then go to the right and left of the baseLocation to
  * check for possible moves.
  */
 public ArrayList<Location> getValidMoveLocations() {
   Grid<Actor> gr = getGrid();
   if (gr == null) {
     return null;
   }
   ArrayList<Location> result = new ArrayList<Location>();
   Location possibleLocation1, possibleLocation2;
   for (int i = 0; i < Location.FULL_CIRCLE; i += Location.RIGHT) {
     Location baseLocation = getLocation();
     for (int counter = 0; counter < 2; counter++) {
       baseLocation = baseLocation.getAdjacentLocation(i);
     }
     possibleLocation1 = baseLocation.getAdjacentLocation(i + Location.LEFT);
     if (gr.isValid(possibleLocation1)) {
       result.add(possibleLocation1);
       if (gr.get(possibleLocation1) instanceof Piece
           && gr.get(possibleLocation1).getColor().equals(getColor())) {
         result.remove(possibleLocation1);
       }
     }
     possibleLocation2 = baseLocation.getAdjacentLocation(i + Location.RIGHT);
     if (gr.isValid(possibleLocation2)) {
       result.add(possibleLocation2);
       if (gr.get(possibleLocation2) instanceof Piece
           && gr.get(possibleLocation2).getColor().equals(getColor())) {
         result.remove(possibleLocation2);
       }
     }
   }
   return result;
 }
Example #2
0
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

      // ### We should indicate the current thread independently of the
      // ### selection, e.g., with an icon, because the user may change
      // ### the selection graphically without affecting the current
      // ### thread.

      super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      if (value == null) {
        this.setText("<unavailable>");
      } else {
        StackFrame frame = (StackFrame) value;
        Location loc = frame.location();
        Method meth = loc.method();
        String methName = meth.declaringType().name() + '.' + meth.name();
        String position = "";
        if (meth.isNative()) {
          position = " (native method)";
        } else if (loc.lineNumber() != -1) {
          position = ":" + loc.lineNumber();
        } else {
          long pc = loc.codeIndex();
          if (pc != -1) {
            position = ", pc = " + pc;
          }
        }
        // Indices are presented to the user starting from 1, not 0.
        this.setText("[" + (index + 1) + "] " + methName + position);
      }
      return this;
    }
Example #3
0
File: set.java Project: wcyuan/Set
    public void mousePressed(MouseEvent e) {
      Message(null, null, 1);
      Message(null, null, 2);
      Message(null, null, 3);
      if (EODtag) {
        deal();
        update(Applet.this.getGraphics());
        return;
      }
      Location l = findloc(e);
      if (l == null) return;
      if (l == button) {
        ShowSet();
        return;
      }

      l.toggle();

      update(Applet.this.getGraphics());

      if (num_selected >= 3) {
        CheckSet();
      }

      lastloc = l;
    }
Example #4
0
  public void onMouseMove(Location point) {

    if (gameOn) {
      theFish.moveTo(point.getX() - theFish.getWidth() / 2, point.getY());

      lastMouse = point;
      currentScore = theFish.getScore();
      score.setText("Score: " + currentScore);
      score.moveTo((canvas.getWidth() - score.getWidth()) / 2, 50);
    }
  }
Example #5
0
 @Override
 public boolean setup(RenderList rl) {
   rl.prepo(Rendered.eyesort);
   rl.prepo(Material.nofacecull);
   Location.goback(rl.state(), "gobx");
   rl.state().put(States.color, null);
   return true;
 }
Example #6
0
 // Walk to the specified location, and set the nextState once you get there
 private void walk(Location loc, State nextState) {
   if (getFarmingArea(loc).contains(getMyPlayer().getLocation())) {
     currentLocation = loc;
     currentState = nextState; // This is the last spot of each run. Break here.
   } else {
     checkEnergy();
     status = "Walking to " + loc.toString() + " herb patch";
     step(pathList);
   }
 }
Example #7
0
 /**
  * method that will be called when mouse drags
  * @param point , the point mouse drag at
  */
 public void onMouseDrag(Location point){
   double xMovement = point.getX() - lastPoint.getX();
   double yMovement = point.getY() - lastPoint.getY();
   //get distance of movement
   
   if(!success){
     if(isGrabbed){
       grabbedPiece.move(xMovement, yMovement);
       lastPoint = point;
     }
   }
   else{
     if(isGrabbed){
       for(Piece p: bp){
         ((BoardPiece)p).move(xMovement, yMovement);
       }
       lastPoint = point;
     }
   }
 }
Example #8
0
 // Teleport to the specified location
 private void teleport(Location loc) {
   status = "Teleporting to " + loc.toString();
   if (magic.castSpell(getSpell(loc))) {
     sleep(random(9000, 11000));
     if (getTeleArea(loc)
         .contains(
             getMyPlayer().getLocation())) { // Teleport successful if player is in the tele area
       currentState = State.WALKING;
       pathList = generatePath(getPath(loc));
     }
   }
 }
Example #9
0
 /** Helper method in order to check for the legality of certain moves made by a King Piece. */
 public ArrayList<Location> getAttackZones() {
   Grid<Actor> gr = getGrid();
   if (gr == null) {
     return null;
   }
   ArrayList<Location> result = new ArrayList<Location>();
   Location possibleLocation1, possibleLocation2;
   for (int i = 0; i < Location.FULL_CIRCLE; i += Location.RIGHT) {
     Location baseLocation = getLocation();
     for (int counter = 0; counter < 2; counter++) {
       baseLocation = baseLocation.getAdjacentLocation(i);
     }
     possibleLocation1 = baseLocation.getAdjacentLocation(i + Location.LEFT);
     if (gr.isValid(possibleLocation1)) {
       result.add(possibleLocation1);
     }
     possibleLocation2 = baseLocation.getAdjacentLocation(i + Location.RIGHT);
     if (gr.isValid(possibleLocation2)) {
       result.add(possibleLocation2);
     }
   }
   return result;
 }
Example #10
0
  /**
   * Returns the location, in pixels, of the centre of a tile at a given location, taking the walls
   * into account.
   */
  private Location<Float> centreForTileAtLocation(
      Location<Integer> location, Board board, double startX, double startY, double tileSize) {
    double tileCentreX = tileSize / 2.0;
    double tileCentreY = tileSize / 2.0;

    if (board.hasWallBetween(location, location.locationInDirection(Direction.Up))) {
      tileCentreY += WallWidth / 4.0;
    }

    if (board.hasWallBetween(location, location.locationInDirection(Direction.Down))) {
      tileCentreY -= WallWidth / 4.0;
    }

    if (board.hasWallBetween(location, location.locationInDirection(Direction.Left))) {
      tileCentreX += WallWidth / 4.0;
    }
    if (board.hasWallBetween(location, location.locationInDirection(Direction.Right))) {
      tileCentreX -= WallWidth / 4.0;
    }

    return new Location<>(
        (float) (startX + tileSize * location.x + tileCentreX),
        (float) (startY + tileSize * location.y + tileCentreY));
  }
Example #11
0
 private void locationButton_actionPerformed(ActionEvent e) {
   this.setVisible(false);
   Location location = new Location();
   location.setVisible(true);
 }
Example #12
0
  @SuppressWarnings("SuspiciousNameCombination")
  // so we don't get warned about using 'WallWidth' in conjunction with height
  @Override
  protected void paintComponent(Graphics g) {

    double width = this.getWidth();
    double height = this.getHeight();

    Graphics2D graphics2D = (Graphics2D) g;

    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Board board = _gameState.board;

    double ratio = (double) board.width / board.height;

    width = Math.min(width, (height * ratio));
    height = Math.min(height, (width / ratio));

    double startX = this.getWidth() / 2 - width / 2;
    double startY = this.getHeight() / 2 - height / 2;

    g.setColor(Color.yellow);
    g.fillRect(round(startX), round(startY), round(width), round(height));

    // Draw the grid.

    g.setColor(Color.black);

    double step = width / board.width;

    for (double x = startX + step; x < startX + width; x += step) {
      g.drawLine(round(x), round(startY), round(x), round(startY + height));
    }
    for (double y = startY + step; y < startY + height; y += step) {
      g.drawLine(round(startX), round(y), round(startX + width), round(y));
    }

    // Draw the room tiles.

    int x = 0;
    for (Board.Tile[] column : board.tiles) {
      int y = 0;
      for (Board.Tile tile : column) {
        boolean hasRoom = tile.room.isPresent();
        boolean isUnaccessibleSpace = tile.connectedLocations.isEmpty();
        if (hasRoom || isUnaccessibleSpace) {
          g.setColor(hasRoom ? Color.lightGray : Color.cyan);
          g.fillRect(
              round(x * step + startX - 0.5),
              round(y * step + startY - 0.5),
              round(step + 1),
              round(step + 1));

          if (tile.isPassageway(board)) {
            g.setColor(Color.darkGray);
            for (int i = 0; i < step; i += 2) {
              g.fillRect(
                  round(x * step + startX - 0.5),
                  round(y * step + startY - 0.5 + i),
                  round(step + 1),
                  1);
            }
          }
        }

        y++;
      }

      x++;
    }

    // Draw the walls.
    // Loop again to draw over what we already have.

    g.setColor(Color.black);
    x = 0;
    for (Board.Tile[] column : board.tiles) {
      int y = 0;
      for (Board.Tile tile : column) {
        Location<Integer> location = new Location<>(x, y);

        if (board.hasWallBetween(location, new Location<>(x + 1, y))) {
          g.fillRect(
              round(startX + step * (x + 1) - WallWidth / 2),
              round(startY + step * y - 0.5),
              WallWidth,
              round(step + 1));
        }

        if (board.hasWallBetween(location, new Location<>(x, y + 1))) {
          g.fillRect(
              round(startX + step * x - 0.5),
              round(startY + step * (y + 1) - WallWidth / 2),
              round(step + 1),
              WallWidth);
        }

        y++;
      }

      x++;
    }

    // Draw the outer walls.

    g.fillRect(round(startX), round(startY), WallWidth, round(height));
    g.fillRect(round(startX), round(startY), round(width), WallWidth);
    g.fillRect(round(startX + width - WallWidth), round(startY), WallWidth, round(height));
    g.fillRect(round(startX), round(startY + height - WallWidth), round(width), WallWidth);

    // Draw the names for the rooms.

    g.setFont(GameFont);
    g.setColor(Color.black);
    FontMetrics fontMetrics = g.getFontMetrics(GameFont);

    for (Room room : Room.values()) {
      Location<Float> centre = board.centreLocationForRoom(room);
      double centreX = (centre.x + 0.5f) * step + startX;
      double centreY = (centre.y + 0.5f) * step + startY;

      String name = room.shortName().toUpperCase();

      Rectangle2D bounds = fontMetrics.getStringBounds(name, g);

      g.drawString(
          name, (int) (centreX - bounds.getCenterX()), (int) (centreY - bounds.getCenterY()));

      double stringBottom = bounds.getCenterY() + centreY;

      this.drawWeaponTokenForRoom(g, board, room, centreX, stringBottom, step);
    }

    // Draw the players.

    boolean shouldPlayMoveSequence = this.shouldPlayMoveSequence();
    for (Player player : _gameState.allPlayers) {
      boolean drawTransparent = false;
      Location<Float> playerLocation;
      if (shouldPlayMoveSequence
          && // We haven't finished animating the move
          player.character == _lastPlayerMoveCharacter) { // and the move is for this character
        // then we need to lerp between two values in the move sequence for the character's
        // position.

        int lowIndex = (int) Math.floor(_moveSequencePosition);
        int highIndex = (int) Math.ceil(_moveSequencePosition);
        double lerpValue = _moveSequencePosition - lowIndex;

        Location<Float> startLocation =
            this.centreForTileAtLocation(
                _lastPlayerMove.locations[lowIndex], board, startX, startY, step);
        Location<Float> endLocation =
            this.centreForTileAtLocation(
                _lastPlayerMove.locations[highIndex], board, startX, startY, step);
        if (Location.distance(startLocation, endLocation)
            > step * 1.5) { // if the tiles aren't adjacent, allowing for some error.
          drawTransparent = true;
        }
        playerLocation = Location.lerp(startLocation, endLocation, (float) lerpValue);
      } else {
        playerLocation =
            this.centreForTileAtLocation(player.location(), board, startX, startY, step);
      }

      this.drawPlayer(g, playerLocation, player.character, step, drawTransparent);
    }

    // If we're supposed to draw the overlay for the paths, do so. Don't draw the overlay while
    // we're animating.
    if (_accessibleTilePaths != null && !shouldPlayMoveSequence) {
      this.drawAccessibleTilesOverlay(g, _accessibleTilePaths, startX, startY, step);
    }
  }
Example #13
0
 public boolean setup(RenderList rl) {
   Location.goback(rl.state(), "gobx");
   rl.prepo(States.xray);
   rl.prepo(clrst);
   return true;
 }