/** * Constructor. * * <p>A pleasant side-effect of constructing a Text() is that consecutive (redundant) colour * escape sequences are collapsed down to just the last colour. * * @param text the text with embedded colour escape sequences. */ public Text(String text) { // By default, text is white. Format format = new Format(Colour.white, 0); for (int i = 0; i < text.length(); ++i) { char c = text.charAt(i); if (c == Colour.ESCAPE_CHAR) { ++i; // Guard against the pathological case of a chat line ending in // Colour.ESCAPE_CHAR. if (i < text.length()) { char code = text.charAt(i); if (Colour.isColour(code)) { format.setColour(Colour.getByCode(code)); // Setting the colour disables any style attributes. format.setStyles(0); } // Note: different from Format.isAttribute() else if (isAttribute(code)) { format.applyStyle(code); } // else: silently delete format codes we don't understand. // At the time of writing, no such codes exist. } } else { // An ordinary, non-colour-escape character. _unformatted.append(c); _colourStyles.append(format.getColourStyle()); } } // for } // Text
public void setpalette() { int ind = colorindices.length; javaColours = new Color[ind]; epsColours = new double[ind][3]; for (int i = 0; i < ind; i++) { System.out.println("color index " + colorindices[i]); javaColours[i] = palette.chooseJavaColour(colorindices[i]); epsColours[i] = palette.chooseEPSColour(colorindices[i]); } }
/** * Returns the MoveDouble associated with this SaveMoveDouble. * * @return the MoveDouble associated with this SaveMoveDouble. */ @Override public Move move() { if (moves.size() < 2) return null; SaveMoveTicket move1 = moves.get(0); SaveMoveTicket move2 = moves.get(1); MoveDouble move = MoveDouble.instance( Colour.valueOf(super.colour), (MoveTicket) move1.move(), (MoveTicket) move2.move()); return move; }
public void placeBet(Player p, Field fields[], int value) throws NotEnoughChipsException, TooManyChipsException, TableFullException, NoMoreBetsException { if (currentChipsOnTable() + value > maxChipsOnTable) throw new TooManyChipsException(); if (!players.keySet().contains(p) && players.size() == MAX_PLAYERS) throw new TableFullException(); if (isBallRolling() && (timer.getTimeInMillis() - ballStartedRolling > CUT_OFF_TIME)) throw new NoMoreBetsException(); if (!walletService.isAvailable(p, value)) throw new NotEnoughChipsException(); walletService.adjustBalance(p, -1 * value); players.put(p, Colour.values()[players.size()]); for (Field field : fields) { if (betsByFields.get(field) == null) { betsByFields.put(field, new ArrayList<Bet>()); } betsByFields.get(field).add(new Bet(p, value, getBetType(fields))); } waitingForPlayersToComplete.add(p); }
/** * Returns the MoveTicket associated with this SaveMoveTicket. * * @return the MoveTicket associated with this SaveMoveTicket. */ @Override public Move move() { MoveTicket move = MoveTicket.instance(Colour.valueOf(super.colour), Ticket.valueOf(ticket), target); return move; }
/** * Returns the MovePass associated with this SaveMovePass. * * @return the MovePass associated with this SaveMovePass. */ @Override public Move move() { return MovePass.instance(Colour.valueOf(super.colour)); }
/** * Constructs a new SaveMove object. * * @param colour the colour of the player to whom this move belongs. */ public SaveMove(Colour colour) { this.colour = colour.toString(); }
/** * Decolourises the text * * @param text The text to decolourise * @return The decolourised text */ public static String decolourise(String text) { return Colour.stripColour(Colour.translateAlternateColourCodes('&', text)); }
@Override public Colour getImageColour() { return Colour.valueOf(this.colour + "VPower"); }
/** * Computes the colour of the pixel at (x,y) where each coordinate is defined to be in the range * (-0.5, +0.5). * * @param x The x-coordinate, between -0.5 and +0.5. * @param y The y-coordinate, between -0.5 and +0.5. * @return The colour at the given pixel. */ private Colour getPixelColour(double x, double y) { Colour c = Colour.pool.borrow().reset(Colour.TRANSPARENT); Vector3 ray = Vector3.pool.borrow().reset(x, -y, 1.0); ray.normalize(); Vector3 intersection = raytrace(ray); if (intersection != null) { // we intersected with the planet. Now we need to work out the colour at this point // on the planet. Colour t = queryTexture(intersection); double intensity = lightSphere(intersection); c.reset(1.0, t.r * intensity, t.g * intensity, t.b * intensity); Colour.pool.release(t); if (mAtmospheres != null) { Vector3 surfaceNormal = Vector3.pool.borrow().reset(intersection); surfaceNormal.subtract(mPlanetOrigin); surfaceNormal.normalize(); Vector3 sunDirection = Vector3.pool.borrow().reset(mSunOrigin); sunDirection.subtract(intersection); sunDirection.normalize(); final int numAtmospheres = mAtmospheres.size(); for (int i = 0; i < numAtmospheres; i++) { final Atmosphere atmosphere = mAtmospheres.get(i); Colour atmosphereColour = atmosphere.getInnerPixelColour( x + 0.5, y + 0.5, intersection, surfaceNormal, sunDirection); Colour.blend(c, atmosphereColour); Colour.pool.release(atmosphereColour); } Vector3.pool.release(surfaceNormal); Vector3.pool.release(sunDirection); } } else if (mAtmospheres != null) { // if we're rendering an atmosphere, we need to work out the distance of this ray // to the planet's surface double u = Vector3.dot(mPlanetOrigin, ray); Vector3 closest = Vector3.pool.borrow().reset(ray); closest.scale(u); double distance = (Vector3.distanceBetween(closest, mPlanetOrigin) - mPlanetRadius); Vector3 surfaceNormal = Vector3.pool.borrow().reset(closest); surfaceNormal.subtract(mPlanetOrigin); surfaceNormal.normalize(); Vector3 sunDirection = Vector3.pool.borrow().reset(mSunOrigin); sunDirection.subtract(closest); sunDirection.normalize(); final int numAtmospheres = mAtmospheres.size(); for (int i = 0; i < numAtmospheres; i++) { final Atmosphere atmosphere = mAtmospheres.get(i); Colour atmosphereColour = atmosphere.getOuterPixelColour(x + 0.5, y + 0.5, surfaceNormal, distance, sunDirection); Colour.blend(c, atmosphereColour); Colour.pool.release(atmosphereColour); } Vector3.pool.release(closest); Vector3.pool.release(surfaceNormal); Vector3.pool.release(sunDirection); } Vector3.pool.release(ray); Vector3.pool.release(intersection); return c; }
@Override public String toString() { return colour.toString() + " King @ " + position; }
@Override public String print() { return "K" + colour.playerNumber(); }