private Action scanArenaColByCol(Robot robot) {

    Action actionForTentativeTurn = actionForTentiveTurn(robot);
    if (actionForTentativeTurn != null) return actionForTentativeTurn;

    if (robotOnArenaEdge(robot, headingOrientation)) {
      Orientation current = robot.getCurrentOrientation();
      if (!current.toOppsite().equals(headingOrientation)) {
        return Action.TURN_LEFT;
      } else {
        headingOrientation = headingOrientation.toOppsite();
        trackColID += robot.getDiameterInCellNum();

        // Whole arena has been explored
        if (trackColID >= this.exploredMap.getColumnCount()) return null;
      }
    }

    int currentSouthWestColID = robot.getSouthWestBlock().getColID();
    if (currentSouthWestColID < trackColID) {
      return moveToOrientation(robot, Orientation.EAST, headingOrientation);
    } else if (currentSouthWestColID == trackColID) {
      return moveToOrientation(robot, headingOrientation, Orientation.EAST);
    } else {
      // currentSouthWestColID > trackColID
      return moveToOrientation(robot, Orientation.WEST, headingOrientation);
    }
  }
  private Action moveToOrientation(
      Robot robot, Orientation firstOrientation, Orientation secondOrientation) {

    Direction preferedDirection = getPreferedDirection(firstOrientation, secondOrientation);

    Orientation currentOrientation = robot.getCurrentOrientation();
    //		System.out.println("Current Orientation = " + currentOrientation.toString());
    //		System.out.println("First Orientation = " + firstOrientation.toString());
    //		System.out.println("Second Orientation = " + secondOrientation.toString());

    if (currentOrientation.equals(firstOrientation)) {

      return moveTowardsDirectionInOrder(
          Direction.AHEAD, preferedDirection, oppoDirection(preferedDirection), robot);
    } else if (currentOrientation.equals(secondOrientation)) {

      return moveTowardsDirectionInOrder(
          oppoDirection(preferedDirection), Direction.AHEAD, preferedDirection, robot);
    } else if (currentOrientation.toOppsite().equals(firstOrientation)) {

      return moveTowardsDirectionInOrder(
          oppoDirection(preferedDirection), Direction.AHEAD, preferedDirection, robot);
    } else if (currentOrientation.toOppsite().equals(secondOrientation)) {

      return moveTowardsDirectionInOrder(
          preferedDirection, Direction.AHEAD, oppoDirection(preferedDirection), robot);
    }
    assert (false) : "Should not reach here. No other circumstance";
    return null;
  }
Exemplo n.º 3
0
 void advance() {
   do {
     x += o.getDx();
     y += o.getDy();
   } while (!game.getBoard().getTile(y, x).equals(Tile.NONE)
       || placedTiles.get(new Point(x, y)) != null);
 }
Exemplo n.º 4
0
 /** @param name The new name of the units. Defaults to DEFAULT is there is no match. */
 public void setOrientation(String name) {
   for (Orientation orientation : Orientation.values()) {
     if (orientation.getName().equals(name)) {
       this.orientation = orientation;
       return;
     }
   }
   this.orientation = Orientation.DEFAULT;
 }
  private boolean existsCellOnOrientaion(Robot robot, Orientation ori, CellState state) {
    Boolean needExplore = null;
    if (robotOnArenaEdge(robot, ori)) return false;
    if (ori.equals(Orientation.NORTH)) needExplore = existsCellOnTheNorth(robot, state);
    if (ori.equals(Orientation.WEST)) needExplore = existsCellOnTheWest(robot, state);
    if (ori.equals(Orientation.SOUTH)) needExplore = existsCellOnTheSouth(robot, state);
    if (ori.equals(Orientation.EAST)) needExplore = existsCellOnTheEast(robot, state);

    return needExplore;
  }
 // Return the new orientation based on the original orientation and its relative direction
 private static Orientation orientationOnDirection(Orientation original, Direction direction) {
   if (direction == Direction.AHEAD) {
     return original.clone();
   } else if (direction == Direction.LEFT) {
     return original.relativeToLeft();
   } else if (direction == Direction.RIGHT) {
     return original.relativeToRight();
   } else {
     assert (false) : "Should not reach here";
   }
   return null;
 }
 private Direction getPreferedDirection(
     Orientation firstOrientation, Orientation secondOrientation) {
   Direction preferedDirection = Direction.NULL;
   if (firstOrientation.relativeToLeft().equals(secondOrientation)) {
     preferedDirection = Direction.LEFT;
   } else if (firstOrientation.relativeToRight().equals(secondOrientation)) {
     preferedDirection = Direction.RIGHT;
   } else {
     assert (false) : "Two Prefered Orientation should be adjacent";
   }
   return preferedDirection;
 }
  public void move() {
    if (last_move_time == null || last_move_time.doubleValue() < world.time) {
      last_move_time = new Double(world.time);
      double max_dist, dist_right, dist_left, theta, x, y, dist_diff;
      double delta_theta, turn_radius, new_theta, new_x, new_y;
      Location location;
      Orientation orientation;

      orientation = orientation();
      location = location();

      max_dist = max_speed / world.ticks_per_second;
      dist_right = right_motor.output() * max_dist;
      dist_left = left_motor.output() * max_dist;
      theta = orientation.theta;
      x = location.x;
      y = location.y;
      old_location.x = x;
      old_location.y = y;
      dist_diff = dist_right - dist_left;

      //			System.out.println("dist_diff: " + dist_diff);

      delta_theta = dist_diff / wheel_base;
      if (Math.abs(dist_diff) < .0001) {
        turn_radius = 0.0;
      } else {
        turn_radius = (dist_right / delta_theta) - (wheel_base / 2);
      }

      //			System.out.println("turn_radius: " + turn_radius);

      new_theta = theta + delta_theta;
      if (turn_radius == 0.0) {

        //				System.out.println("turn_radius == 0");

        new_x = x + Math.cos(theta) * dist_left;
        new_y = y + Math.sin(theta) * dist_left;
      } else {

        //				System.out.println("new_theta= " + new_theta + " theta= " + theta);

        new_x = x + ((Math.sin(new_theta) - Math.sin(theta)) * turn_radius);
        new_y = y - ((Math.cos(new_theta) - Math.cos(theta)) * turn_radius);
      }
      orientation.theta = new_theta;
      location.x = new_x;
      location.y = new_y;

      maybe_fire_guns();
    }
  }
Exemplo n.º 9
0
 public static void setOrientation(Element el, Orientation value) {
   // iOS6 & Android < 4.4
   switch (value) {
     case HORIZONTAL:
       el.getStyle().setProperty("WebkitBoxOrient", "horizontal");
       break;
     case VERTICAL:
       el.getStyle().setProperty("WebkitBoxOrient", "vertical");
       break;
     default:
       throw new RuntimeException();
   }
   setFlexProperty(el, Orientation.getCssProperty(), value.getCssValue());
 }
  private void init(Context context, AttributeSet attrs, int defStyle) {
    TypedArray typedArray =
        context.obtainStyledAttributes(attrs, R.styleable.IncreasingSeekBar, defStyle, 0);
    try {
      mOrientation =
          Orientation.fromId(
              typedArray.getInt(
                  R.styleable.IncreasingSeekBar_isb_orientation, Orientation.HORIZONTAL.id));
      mMaxRang = typedArray.getInt(R.styleable.IncreasingSeekBar_isb_max, DEF_MAX_RANG);
      mCurrValue = typedArray.getInt(R.styleable.IncreasingSeekBar_isb_curr_value, 0);
      mGapWidthPercent =
          typedArray.getFraction(
              R.styleable.IncreasingSeekBar_isb_gap_percent, 1, 1, DEF_GAP_PERCENT);
      mAllowUserTouch =
          typedArray.getBoolean(R.styleable.IncreasingSeekBar_isb_allow_user_touch, true);
      mDrawBorder = typedArray.getBoolean(R.styleable.IncreasingSeekBar_isb_draw_border, false);
      mBorderColor = typedArray.getColor(R.styleable.IncreasingSeekBar_isb_border_color, DEF_COLOR);
      mBorderWidth =
          typedArray.getDimension(R.styleable.IncreasingSeekBar_isb_border_width, DEF_BORDER_WIDTH);
      mMainColor = typedArray.getColor(R.styleable.IncreasingSeekBar_isb_color, DEF_COLOR);
      mStartColor = typedArray.getColor(R.styleable.IncreasingSeekBar_isb_color_start, -1);
      mEndColor = typedArray.getColor(R.styleable.IncreasingSeekBar_isb_color_end, -1);

    } finally {
      typedArray.recycle();
    }

    mBarItemPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBarItemPaint.setColor(mMainColor);
    mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setStrokeWidth(mBorderWidth);
    mBarItemPaint.setColor(mBorderColor);
  }
Exemplo n.º 11
0
 public static Orientation fromIndex(int index) {
   Orientation[] values = Orientation.values();
   if (index < 0 || index >= values.length) {
     throw new IndexOutOfBoundsException();
   }
   return values[index];
 }
Exemplo n.º 12
0
  @Override
  public JComponent createUI(
      DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) {
    // Create the main panel
    JComponent component = new JPanel(new MigLayout("fill"));

    boolean isOptional = false;
    if (inputOrOutput instanceof InputDescriptionType) {
      isOptional =
          ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0"));
    }
    // Display the SourceCA into a JTextField
    JTextField jtf = new JTextField();
    jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue());
    // "Save" the CA inside the JTextField
    jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap);
    URI uri = URI.create(inputOrOutput.getIdentifier().getValue());
    jtf.getDocument().putProperty(URI_PROPERTY, uri);
    // add the listener for the text changes in the JTextField
    jtf.getDocument()
        .addDocumentListener(
            EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document"));
    if (isOptional) {
      if (dataMap.containsKey(uri)) {
        jtf.setText(dataMap.get(uri).toString());
      }
    }

    GeometryData geometryData = null;
    if (inputOrOutput instanceof InputDescriptionType) {
      geometryData =
          (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue();
    }
    // If the DescriptionType is an output, there is nothing to show, so exit
    if (geometryData == null) {
      return null;
    }

    component.add(jtf, "growx");

    if (orientation.equals(Orientation.VERTICAL)) {
      JPanel buttonPanel = new JPanel(new MigLayout());

      // Create the button Browse
      JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE));
      // "Save" the sourceCA and the JTextField in the button
      pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf);
      pasteButton.setBorderPainted(false);
      pasteButton.setContentAreaFilled(false);
      pasteButton.setMargin(new Insets(0, 0, 0, 0));
      // Add the listener for the click on the button
      pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", ""));
      buttonPanel.add(pasteButton);

      component.add(buttonPanel, "dock east");
    }

    return component;
  }
  private boolean robotOnArenaEdge(Robot robot, Orientation ori) {
    if (ori.equals(Orientation.NORTH)) {
      return robot.getSouthWestBlock().getRowID() == robot.getDiameterInCellNum() - 1;
    }

    if (ori.equals(Orientation.EAST)) {
      return robot.getSouthWestBlock().getColID()
          == this.exploredMap.getColumnCount() - robot.getDiameterInCellNum();
    }

    if (ori.equals(Orientation.SOUTH)) {
      return robot.getSouthWestBlock().getRowID() == this.exploredMap.getRowCount() - 1;
    }

    if (ori.equals(Orientation.WEST)) {
      return robot.getSouthWestBlock().getColID() == 0;
    }
    assert (false) : "No other direction...";
    return false;
  }
Exemplo n.º 14
0
  private boolean contains(Node x, Point2D p, Orientation orientation) {
    if (x == null) {
      return false;
    }

    if (x.p.equals(p)) {
      return true;
    }

    int cmp = compare(p, x.p, orientation);
    Orientation nextOrientation = orientation.next();

    if (cmp < 0) {
      return contains(x.lb, p, nextOrientation);
    } else {
      return contains(x.rt, p, nextOrientation);
    }
  }
Exemplo n.º 15
0
  private Point2D findNearest(
      Node x, Point2D p, Point2D nearest, double minDist, Orientation orientation) {
    if (x == null) {
      return nearest;
    }
    Point2D closest = nearest;
    double closestDistance = minDist;
    double distance = x.p.distanceSquaredTo(p);
    if (distance < minDist) {
      closest = x.p;
      closestDistance = distance;
    }
    Node first, second;
    if (orientation == Orientation.LR) {
      if (p.x() < x.p.x()) {
        first = x.lb;
        second = x.rt;
      } else {
        first = x.rt;
        second = x.lb;
      }
    } else {
      if (p.y() < x.p.y()) {
        first = x.lb;
        second = x.rt;
      } else {
        first = x.rt;
        second = x.lb;
      }
    }
    Orientation nextOrientation = orientation.next();
    if (first != null && first.rect.distanceSquaredTo(p) < closestDistance) {
      closest = findNearest(first, p, closest, closestDistance, nextOrientation);
      closestDistance = closest.distanceSquaredTo(p);
    }
    if (second != null && second.rect.distanceSquaredTo(p) < closestDistance) {
      closest = findNearest(second, p, closest, closestDistance, nextOrientation);
    }

    return closest;
  }
Exemplo n.º 16
0
 @Override
 public void onBeginParsing(
     String orientation,
     Color backgroundColor,
     int width,
     int height,
     int tileWidth,
     int tileHeight) {
   try {
     this.orientation = Orientation.valueOf(orientation.toUpperCase());
   } catch (Exception e) {
     this.orientation = Orientation.UNKNOWN;
   }
   if (backgroundColor != null) {
     this.backgroundColor = backgroundColor;
   }
   this.width = width;
   this.height = height;
   this.tileWidth = tileWidth;
   this.tileHeight = tileHeight;
 }
  private void renderCupola(CupolaTE te) {
    if (te.isSlave()) return;
    final Tessellator instance = Tessellator.getInstance();

    final BlockPos pos = te.getPos();
    final World world = te.getWorld();

    // Lighting
    final float brightness = ModBlock.cupola.getMixedBrightnessForBlock(world, pos);
    final int skyLight = world.getLightBrightnessForSkyBlocks(pos, 0);
    final int skyLightLSB = skyLight % 65536;
    final int skyLightMSB = skyLight / 65536;

    final WorldRenderer worldRenderer = instance.getWorldRenderer();
    worldRenderer.setColorOpaque_F(brightness, brightness, brightness);
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, skyLightLSB, skyLightMSB);

    // Open Render buffer
    GL11.glPushMatrix();

    // Inherent adjustments to model
    GL11.glScalef(SCALE.left, SCALE.middle, SCALE.right);
    GL11.glTranslatef(OFFSET.left, OFFSET.middle, OFFSET.right);

    // Orient the model to match the placement
    final IBlockState metadata = world.getBlockState(pos);
    final Orientation orientation = Orientation.getdecodedOrientation(metadata);

    GL11.glRotatef(getAngleFromOrientation(orientation), 0.0F, 1.0F, 0.0F);

    // Bind the texture
    if (te.isActive()) bindTexture(TEXTURE_ACTIVE);
    else bindTexture(TEXTURE);

    // Render
    model.render();

    // Close Render Buffer
    GL11.glPopMatrix();
  }
Exemplo n.º 18
0
  public void init() {
    assert name != null;
    assert type != null;
    assert legend != null;
    assert database != null;
    assert query != null;

    try {
      actualType = Type.valueOf(type);
      generatorClass = actualType.getGeneratorClass();
    } catch (Exception e) {
      logger.error("Invalid chart type: " + type, e);
    }

    if (orientation != null) {
      try {
        actualOrientation = Orientation.valueOf(orientation);
      } catch (Exception e) {
        logger.error("Invalid orientation: " + actualOrientation, e);
      }
    }
    actualDatabase = DatabaseLogic.findDatabaseByName(persistence.getModel(), database);
  }
Exemplo n.º 19
0
  private void draw(Node x, Orientation orientation) {
    if (x == null) {
      return;
    }

    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.setPenRadius(0.01);
    x.p.draw();

    if (orientation == Orientation.LR) {
      StdDraw.setPenColor(StdDraw.RED);
      StdDraw.setPenRadius(0.001);
      StdDraw.line(x.p.x(), x.rect.ymin(), x.p.x(), x.rect.ymax());
    } else {
      StdDraw.setPenColor(StdDraw.BLUE);
      StdDraw.setPenRadius(0.001);
      StdDraw.line(x.rect.xmin(), x.p.y(), x.rect.xmax(), x.p.y());
    }

    Orientation next = orientation.next();
    draw(x.lb, next);
    draw(x.rt, next);
  }
Exemplo n.º 20
0
  private Node put(Node x, Point2D p, Orientation orientation) {
    if (x == null) {
      ++size;
      return new Node(p);
    }

    if (x.p.equals(p)) {
      return x;
    }

    int cmp = compare(p, x.p, orientation);
    Orientation nextOrientation = orientation.next();

    if (cmp < 0) {
      x.lb = put(x.lb, p, nextOrientation);

      if (x.lb.rect == null) {
        if (orientation == Orientation.LR) {
          x.lb.rect = new RectHV(x.rect.xmin(), x.rect.ymin(), x.p.x(), x.rect.ymax());
        } else {
          x.lb.rect = new RectHV(x.rect.xmin(), x.rect.ymin(), x.rect.xmax(), x.p.y());
        }
      }
    } else {
      x.rt = put(x.rt, p, nextOrientation);

      if (x.rt.rect == null) {
        if (orientation == Orientation.LR) {
          x.rt.rect = new RectHV(x.p.x(), x.rect.ymin(), x.rect.xmax(), x.rect.ymax());
        } else {
          x.rt.rect = new RectHV(x.rect.xmin(), x.p.y(), x.rect.xmax(), x.rect.ymax());
        }
      }
    }

    return x;
  }
Exemplo n.º 21
0
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("Fractal");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout layout = new SpringLayout();
    frame.setLayout(layout);

    Orientation nw = new Orientation();
    nw.setOffset(0, 0);
    Orientation sw = new Orientation();
    sw.setOffset(0, regionSize);
    Orientation se = new Orientation();
    se.setOffset(regionSize, regionSize);

    Fractal fractal = new Fractal(regionSize);
    fractal.setOrientations(nw, sw, se);

    layout.putConstraint(SpringLayout.WEST, fractal, 5, SpringLayout.WEST, frame.getContentPane());
    layout.putConstraint(
        SpringLayout.NORTH, fractal, 5, SpringLayout.NORTH, frame.getContentPane());

    layout.putConstraint(SpringLayout.WEST, nw, 5, SpringLayout.EAST, fractal);
    layout.putConstraint(SpringLayout.NORTH, nw, 0, SpringLayout.NORTH, fractal);

    layout.putConstraint(SpringLayout.NORTH, sw, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, sw, 0, SpringLayout.WEST, nw);

    layout.putConstraint(SpringLayout.NORTH, se, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, se, 5, SpringLayout.EAST, sw);

    layout.putConstraint(
        SpringLayout.SOUTH, frame.getContentPane(), 5, SpringLayout.SOUTH, fractal);
    layout.putConstraint(SpringLayout.EAST, frame.getContentPane(), 5, SpringLayout.EAST, se);

    frame.add(nw);
    frame.add(sw);
    frame.add(se);

    frame.add(fractal);

    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
 /**
  * Converts the video orientation into the byte used to transmit int RTP header
  *
  * @return Byte representing the video orientation
  */
 public byte getVideoOrientation() {
   return (byte) ((camera.getValue() << 3) | orientation.getValue());
 }
 /**
  * Parses the byte into a VideoOrientation object
  *
  * @param videoOrientation Byte representing the video Orientation
  * @return VideoOrientation object
  */
 public static VideoOrientation parse(byte videoOrientation) {
   return new VideoOrientation(
       CameraOptions.convert((videoOrientation & 0x08) >>> 3),
       Orientation.convert(videoOrientation & 0x07));
 }
Exemplo n.º 24
0
 /** @return the orientation option value */
 public Orientation getOrientation() {
   String orientation = this.options.getLiteral("orientation");
   return orientation == null
       ? Orientation.HORIZONTAL
       : Orientation.valueOf(orientation.toUpperCase());
 }
Exemplo n.º 25
0
  private void drawTile(IBoard b, GC gc, int x, int y, int xo, int yo, int size) {
    gc.setClipping(xo, yo, size + 1, size + 1);

    Color c = background;
    if (b.getLetterMultiplier(y, x) == 2) c = doubleLetter;
    else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetter;
    else if (b.getLetterMultiplier(y, x) == 4) c = quadLetter;
    else if (b.getWordMultiplier(y, x) == 2) c = doubleWord;
    else if (b.getWordMultiplier(y, x) == 3) c = tripleWord;
    else if (b.getWordMultiplier(y, x) == 4) c = quadWord;
    gc.setBackground(c);
    gc.fillRectangle(xo, yo, size, size);

    c = light;
    if (b.getLetterMultiplier(y, x) == 2) c = doubleLetterLight;
    else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetterLight;
    else if (b.getLetterMultiplier(y, x) == 4) c = quadLetterLight;
    else if (b.getWordMultiplier(y, x) == 2) c = doubleWordLight;
    else if (b.getWordMultiplier(y, x) == 3) c = tripleWordLight;
    else if (b.getWordMultiplier(y, x) == 4) c = quadWordLight;
    gc.setForeground(c);
    gc.drawLine(xo, yo, xo + size, yo);
    gc.drawLine(xo, yo, xo, yo + size);

    gc.setForeground(dark);
    gc.drawLine(xo + size, yo + size, xo + size, yo);
    gc.drawLine(xo + size, yo + size, xo, yo + size);

    Tile tile = b.getTile(y, x);

    if (tile.equals(Tile.NONE)) {
      for (Iterator i = placedTiles.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        Point point = (Point) entry.getKey();
        if (point.x == x && point.y == y) {
          tile = (Tile) entry.getValue();

          DragSource source = new DragSource();
          source.rectangle = new Rectangle(xo, yo, size + 1, size + 1);
          source.x = x;
          source.y = y;
          source.tile = tile;
          dragSources.put(source.rectangle, source);
        }
      }
    }

    boolean highlight = false;
    IGameAction action = game.getLastAction();
    if (action != null && action instanceof MoveAction) {
      MoveAction moveAction = (MoveAction) action;
      MoveResult result = moveAction.getMoveResult();
      Tile[] tiles = result.getPreviousBoardState();
      Move move = result.getMove();
      Orientation orientation = move.getOrientation();
      int dx = orientation.getDx();
      int dy = orientation.getDy();
      int mx = move.getColumn();
      int my = move.getRow();
      for (int i = 0; i < tiles.length; i++) {
        Tile t = tiles[i];
        if (mx == x && my == y && t.equals(Tile.NONE)) {
          highlight = true;
        }
        mx += dx;
        my += dy;
      }
    }

    drawTile(gc, new Rectangle(xo, yo, size + 1, size + 1), tile, highlight);

    if (arrow != null && arrow.x == x && arrow.y == y) {
      drawArrow(gc, xo, yo, size);
    }
  }
Exemplo n.º 26
0
 /**
  * Normally you don't need to set this option because the plugin detects the slider orientation
  * automatically. If the orientation is not correctly detected you can set this option to
  * 'horizontal' or 'vertical'.
  *
  * @param orientation
  * @return instance of the current component
  */
 public Slider setOrientation(Orientation orientation) {
   this.options.putLiteral("orientation", orientation.toString().toLowerCase());
   return this;
 }
Exemplo n.º 27
0
 void backup() {
   do {
     x -= o.getDx();
     y -= o.getDy();
   } while (!game.getBoard().getTile(y, x).equals(Tile.NONE));
 }
Exemplo n.º 28
0
  private void majgrid1(Player player) {
    gridtest = new Grid();
    gridtest = player.getGridJoueur();

    ShipType type = ShipType.AIRCRAFT_CARRIER;
    Ship ship = new Ship(type);
    Orientation orient = Orientation.HORIZONTAL;
    for (int i = 0; i < 10; i++) // ligne
    {
      for (int j = 0; j < 10; j++) // colonne
      {
        if (gridtest.getCell(i, j) instanceof OceanCell) {
          tabbout1[i][j].setIcon(iconeau);
        }
        //                else if(gridtest.getCell(i, j) instanceof TouchOceanCell)
        //                {
        //                    tabbout1[i][j].setIcon(iconeautouch);
        //                }
        //                else if(gridtest.getCell(i, j) instanceof TouchOceanCell)
        //                {
        //                    tabbout1[i][j].setIcon(icondebristouch);
        //                }
        else if (gridtest.getCell(i, j) instanceof ShipCell) {
          ship = ((ShipCell) gridtest.getCell(i, j)).getShip();
          int size = ship.getSize();
          orient = ((ShipCell) gridtest.getCell(i, j)).getOrient();

          if (orient.isHorizontal()) {
            if (ship.getSize() == 2) {
              tabbout1[i][j].setIcon(iconsub1h);
              tabbout1[i][j + 1].setIcon(iconsub2h);
              tabbout1[i][j + 2].setIcon(iconsub3h);
              j = j + 2;

            } else if (ship.getSize() == 3) // battleship
            {
              tabbout1[i][j].setIcon(iconbattle1h);
              tabbout1[i][j + 1].setIcon(iconbattle2h);
              tabbout1[i][j + 2].setIcon(iconbattle3h);
              tabbout1[i][j + 3].setIcon(iconbattle4h);
              j = j + 3;
            } else {
              tabbout1[i][j].setIcon(iconair1h);
              tabbout1[i][j + 1].setIcon(iconair2h);
              tabbout1[i][j + 2].setIcon(iconair3h);
              tabbout1[i][j + 3].setIcon(iconair4h);
              tabbout1[i][j + 4].setIcon(iconair5h);
              j = j + 4;
            }
          }
        }
      }

      for (int i2 = 0; i2 < 10; i2++) // ligne
      {
        for (int j2 = 0; j2 < 10; j2++) // colonne
        {
          if (gridtest.getCell(i2, j2) instanceof ShipCell) {
            ship = ((ShipCell) gridtest.getCell(i2, j2)).getShip();
            orient = ((ShipCell) gridtest.getCell(i2, j2)).getOrient();

            if (!orient.isHorizontal()) {
              if (ship.getSize() == 2) {
                tabbout1[i2][j2].setIcon(iconsub1v);
                tabbout1[i2 + 1][j2].setIcon(iconsub2v);
                tabbout1[i2 + 2][j2].setIcon(iconsub3v);
                i2 = i2 + 2;
              } else if (ship.getSize() == 3) // battleship
              {
                tabbout1[i2][j2].setIcon(iconbattle1v);
                tabbout1[i2 + 1][j2].setIcon(iconbattle2v);
                tabbout1[i2 + 2][j2].setIcon(iconbattle3v);
                tabbout1[i2 + 3][j2].setIcon(iconbattle4v);
                i2 = i2 + 3;
              } else {
                tabbout1[i2][j2].setIcon(iconair1v);
                tabbout1[i2 + 1][j2].setIcon(iconair2v);
                tabbout1[i2 + 2][j2].setIcon(iconair3v);
                tabbout1[i2 + 3][j2].setIcon(iconair4v);
                tabbout1[i2 + 4][j2].setIcon(iconair5v);
                i2 = i2 + 4;
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 29
0
 public Vector_2 perpendicular(Orientation o) {
   if (o.isCounterclockwise() == true) return new Vector_2(-y, x);
   else return new Vector_2(y, -x);
 }
Exemplo n.º 30
0
  // create move based on placed tiles
  private Move createMove() {
    if (game == null) return null;
    if (placedTiles.size() < 1) return null;

    Point[] points = new Point[placedTiles.size()];
    placedTiles.keySet().toArray(points);

    IBoard board = game.getBoard();
    boolean horizontal = true;
    boolean vertical = true;

    // vertical?
    for (int i = 1; i < points.length; i++) {
      Point point = points[i];
      if (point.x != points[i - 1].x) {
        vertical = false;
        break;
      }
    }

    // horizontal?
    for (int i = 1; i < points.length; i++) {
      Point point = points[i];
      if (point.y != points[i - 1].y) {
        horizontal = false;
        break;
      }
    }

    // scattered and invalid?
    if (!horizontal && !vertical) {
      return null;
    }

    // ambiguous?
    if (horizontal && vertical) {
      int x = points[0].x;
      int y = points[0].y;
      if (board.getTile(y, x - 1).equals(Tile.NONE) && board.getTile(y, x + 1).equals(Tile.NONE)) {
        horizontal = false;
      }
      if (board.getTile(y - 1, x).equals(Tile.NONE) && board.getTile(y + 1, x).equals(Tile.NONE)) {
        vertical = false;
      }
      // not adjacent to anything?
      if (!horizontal && !vertical) {
        return null;
      }
      // still ambiguous?
      if (horizontal && vertical) {
        // just pick one
        horizontal = false;
      }
    }

    Orientation orientation = vertical ? Orientation.VERTICAL : Orientation.HORIZONTAL;
    int dx = orientation.getDx();
    int dy = orientation.getDy();

    // find first placed tile
    int x = points[0].x;
    int y = points[0].y;
    for (int i = 1; i < points.length; i++) {
      Point point = points[i];
      if (point.x < x) x = point.x;
      if (point.y < y) y = point.y;
    }

    // traverse on-board tiles backwards
    while (!board.getTile(y - dy, x - dx).equals(Tile.NONE)) {
      x -= dx;
      y -= dy;
    }

    int row = y;
    int column = x;

    // build word
    StringBuffer b = new StringBuffer();
    while (true) {
      Point point = new Point(x, y);
      Tile tile = board.getTile(y, x);
      if (tile == null || tile.equals(Tile.NONE)) {
        tile = placedTiles.get(point);
      }
      if (tile == null || tile.equals(Tile.NONE)) {
        break;
      }
      b.append(tile);
      x += dx;
      y += dy;
    }

    Move move = new Move();
    move.setColumn(column);
    move.setRow(row);
    move.setOrientation(orientation);
    move.setWord(Convert.toTiles(b.toString()));
    return move;
  }