private GLabel prompt(String endGame) { GLabel prompt = new GLabel(endGame); prompt.setFont("Times-Bold-50"); double x = (WIDTH - prompt.getWidth()) / 2; double y = HEIGHT * 4.0 / 5.0; prompt.setLocation(x, y); return prompt; }
public void showMessage(String message) { pausePlay(); gameMessage.setLabel(message); gameMessage.setLocation( WIDTH / 2 - gameMessage.getWidth() / 2, HEIGHT / 2 - gameMessage.getHeight() / 2); add(gameMessage); }
private void paint_label() { /* Write an inscription in the lower right corner of the window * From the window width and subtract the width of the label we get the start * point of the X inscription. (similar to height) */ GLabel label = new GLabel("Flag of " + COUNTRY, FLAG_WIDTH, getHeight()); label.setFont(new Font("Tamoha", Font.BOLD, 18)); label.setLocation((getWidth() - label.getWidth()), (getHeight() - label.getHeight() / 2)); add(label); }
/** The method accepts a string and displays the green text in the center of the screen */ private GLabel createMessage(String message) { GLabel text = new GLabel(message); text.setFont("Arial Black-20"); text.setColor(Color.GREEN); double x = (WIDTH - text.getWidth()) / 2; double y = (HEIGHT - text.getDescent()) / 2; text.setLocation(x, y); add(text); return text; }
/** Displays the amount of points on the screen in text form */ private GLabel createScore(String score) { GLabel text = new GLabel(score); text.setFont("Arial Black-12"); text.setColor(Color.black); double x = (WIDTH - text.getWidth()) / 2; double y = HEIGHT - text.getDescent(); text.setLocation(x, y); add(text); return text; }
public GLabel makeLetterLabel(int numDivs) { boolean get = randgen.nextBoolean(); String ga; if (get) ga = "G"; else ga = "A"; GLabel getOrAvoid = new GLabel(ga); getOrAvoid.setFont(new Font("Cambria", Font.BOLD, 24)); double locx = randgen.nextDouble(INDENT, getWidth() - getOrAvoid.getWidth()); int whichdiv = randgen.nextInt(1, numDivs); double locy = whichdiv * getHeight() / numDivs; getOrAvoid.setLocation(locx, locy); return getOrAvoid; }
public void restartGame() { getGCanvas().removeAll(); lives = NTURNS; bricksRemaining = NBRICK_ROWS * NBRICKS_PER_ROW; Color[] colors = {Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN}; int xOffset = BRICK_SEP / 2; int yOffset = BRICK_Y_OFFSET; for (int row = 0; row < NBRICK_ROWS; row++) { Color color = colors[(int) ((double) colors.length / (double) NBRICK_ROWS * row)]; for (int col = 0; col < NBRICKS_PER_ROW; col++) { BreakoutBrick rect = new BreakoutBrick( col * BRICK_WIDTH + col * BRICK_SEP + xOffset, row * BRICK_HEIGHT + row * BRICK_SEP + yOffset, BRICK_WIDTH, BRICK_HEIGHT); rect.setColor(color); rect.setFilled(true); add(rect); } } paddle = new BreakoutPaddle( WIDTH / 2 - PADDLE_WIDTH / 2, HEIGHT - PADDLE_HEIGHT - PADDLE_Y_OFFSET, PADDLE_WIDTH, PADDLE_HEIGHT); add(paddle); ball = new BreakoutBall(WIDTH / 2 - BALL_RADIUS, HEIGHT / 2 - BALL_RADIUS, BALL_RADIUS); add(ball); lifeDisplay.setLabel(String.format("Lives remaining: %d", lives)); lifeDisplay.setLocation(WIDTH - lifeDisplay.getWidth() - 10, lifeDisplay.getHeight() + 10); add(lifeDisplay); resumePlay(); }
private GLabel showLifeCount(int life) { GLabel lifeCount = new GLabel("Life Count: " + life); lifeCount.setFont("Times-15"); lifeCount.setLocation(10, lifeCount.getAscent() + 10); return lifeCount; }