コード例 #1
0
ファイル: bogglegui.cpp プロジェクト: jacksonsierra/Boggle
    /*
     * Creates all cubes in position, including a blank letter centered in
     * the middle of each cube.  Initially the cubes are not highlighted.
     */
    static void setupLetterCubes() {
        double lineWidth = 2;
        double cubeSize = gState.cubeSize - lineWidth;
        double cubeY = gState.board.y + BOARD_BORDER/2;
        for (int row = 0; row < gState.rowCount; row++) {
            double cubeX = gState.board.x + BOARD_BORDER/2;
            for (int col = 0; col < gState.columnCount; col++) {
                // display the letter cubes as rounded rectangles
                double cubeRoundRadius = gState.cubeSize/5;
                GRoundRect* rect = new GRoundRect(cubeX, cubeY, cubeSize,
                                                  cubeSize, cubeRoundRadius * 2);
                rect->setLineWidth(lineWidth);
                rect->setColor("Black");
                rect->setFilled(true);
                rect->setFillColor(DIE_COLOR);
                gwp->add(rect);
                letterCubes[row][col].rect = rect;

                // draw the letter on the cube
                GLabel* label = new GLabel("M");   // start as "M" for getWidth
                label->setFont(CUBE_FONT + "-" + integerToString(int(gState.fontSize)));
                label->setColor(LETTER_COLOR);
                label->setLocation(cubeX + gState.cubeSize/2 - label->getWidth()/2,
                                   cubeY + gState.cubeSize/2 + 0.4 * gState.fontSize);
                label->setLabel(" ");
                gwp->add(label);
                letterCubes[row][col].label = label;
                cubeX += (int) cubeSize + lineWidth;
            }
            cubeY += (int) cubeSize + lineWidth;
        }
    }
コード例 #2
0
ファイル: bogglegui.cpp プロジェクト: jacksonsierra/Boggle
    /*
     * Labels player word list with specified name and draws a line underneath.
     * Also sets up the score label for the specified player.
     */
    static void setupPlayerLabels(Player player, string name) {
        gwp->setColor(LABEL_COLOR);
        gwp->drawLine(gState.scoreBox[player].x, gState.scoreBox[player].y,
                      gState.scoreBox[player].x + gState.scoreBox[player].w,
                      gState.scoreBox[player].y);
        GLabel* lab = new GLabel(name);
        lab->setFont(SCORE_FONT + "-" + integerToString(SCORE_FONT_SIZE));
        gwp->add(lab, gState.scoreBox[player].x, gState.scoreBox[player].y + LABEL_DY);

        GLabel** scoreLabel = player == COMPUTER ? &computerScoreLabel : &humanScoreLabel;
        *scoreLabel = new GLabel("0");
        (*scoreLabel)->setFont(SCORE_FONT + "-" + integerToString(SCORE_FONT_SIZE));
        (*scoreLabel)->setColor(LABEL_COLOR);
        int offset = 32;
        gwp->add(*scoreLabel, gState.scoreBox[player].x + gState.scoreBox[player].w - offset,
                 gState.scoreBox[player].y + LABEL_DY);
    }
コード例 #3
0
void drawGraph(Vector<pair<string, int> > operands, pair<double, double> scope, int scale, string formula) {
    GWindow graphicsWindow(800, 600);
    graphicsWindow.setColor("BLACK");
    pair<double, double> center = drawCoordinateSystem(graphicsWindow, scale);
    GLabel* formulaMark = new GLabel("y = " + formula, 20, 30);
    formulaMark->setFont("Courier New");
    graphicsWindow.add(formulaMark);
    graphicsWindow.setColor("RED");
    double prewX = scope.first;
    double prewY = calculateFunction(operands, prewX);
    for (double x = scope.first + 0.01; x <= scope.second; x += 0.01) {
        double y = calculateFunction(operands, x);
        graphicsWindow.drawLine(center.first + prewX * scale, center.second - prewY * scale,
                                center.first + x * scale, center.second - y * scale);
        prewX = x;
        prewY = y;
    }
}
コード例 #4
0
ファイル: bogglegui.cpp プロジェクト: jacksonsierra/Boggle
 void recordWord(string word, Player player) {
     ensureInitialized();
     if (player != HUMAN && player != COMPUTER) {
         error("recordWord called with invalid player argument.");
     }
     word = toLowerCase(trim(word));
     GLabel* label = new GLabel(word);
     label->setFont(WORD_FONT + "-" + integerToString(WORD_FONT_SIZE));
     label->setColor(WORD_COLOR);
     int wordCountInRow = int(gState.scoreBox[player].w/gState.wordColumnWidth);
     int row = gState.wordCount[player] / wordCountInRow;
     int col = gState.wordCount[player] % wordCountInRow;
     gState.wordCount[player]++;
     gwp->add(label, gState.scoreBox[player].x + col * gState.wordColumnWidth,
                   gState.scoreBox[player].y + (row + 1) * WORD_FONT_SIZE + WORD_DY);
     if (col == wordCountInRow - 1) {
         gwp->repaint();
     }
     recordedWordLabels.add(label);
 }