Пример #1
0
bool GraphWidget::loadFrom(QString filename)
{
    //load size

    std::ifstream fichier(filename.toStdString().c_str(), std::ios::in);  // on ouvre en lecture

    if(fichier)  // si l'ouverture a fonctionné
    {
            int contenu;  // déclaration d'une chaîne qui contiendra la ligne lue
            fichier >> contenu;
            width=contenu;
            fichier >> contenu;
            heigth=contenu;

            initializeCells(scene());

            while(!fichier.eof())
            {
                int i, j;
                fichier >> i;
                if(fichier.eof())
                {
                    qDebug()<<"Error when loading the file. Invalid syntax.";
                    return false;
                }

                fichier >> j;
                cells[i][j]->setState(wall);
            }

            fichier.close();
    }
    else
    {
Пример #2
0
void GameBoard::copyFrom(const GameBoard & src) {
    mWidth = src.mWidth;
    mHeight = src.mHeight;
    
    initializeCells();

    for (size_t i = 0; i < mWidth; i++) {
        for (size_t j = 0; j < mHeight; j++) {
            if (src.mCells[i][j])
                mCells[i][j] = src.mCells[i][j]->clone();
        }
    }
}
Пример #3
0
bool GraphWidget::loadQuestion()
{
    //box: do you want to load a file?
    int reponse = QMessageBox::question(this, "Map", "Do you want to load an existing map ?", QMessageBox ::Yes | QMessageBox::No);

    if (reponse == QMessageBox::No)
    {
        initializeCells(scene());
        return false;
    }
    //choose file
    QString fichier = QFileDialog::getOpenFileName(this, "Open an existing map", QString(), "Text (*.txt)");
    //if success
    if(loadFrom(fichier))
        return true;
    return false;
}
Пример #4
0
int main(int argc, char *argv[])
{
  FILE *fp = fopen(argv[2], "r");
  int height = countLines(fp);
  int width = numCharsPerLine(fp);
  WBCell **cells = initializeCells(fp, height, width);
  fclose(fp);
  // printCells(cells, height, width);


  FILE *lexiconFilePtr = fopen(LEXICON_FILENAME, "r");
  TreeNode *lexTree = buildTreeFromFile(lexiconFilePtr);
  fclose(lexiconFilePtr);

  solvePuzzle(lexTree, cells, height, width, atoi(argv[1]));

  freeCells(cells, height, width);
  freeTree(lexTree);
  return 0;
}
Пример #5
0
GameBoard::GameBoard(size_t inWidth, size_t inHeight) : mWidth(inWidth), mHeight(inHeight) {
    initializeCells();
}
Пример #6
0
//////////////////////////////////////////////////////////////////////////////
//                         Program Entry Point
int main(int argc, char **argv)
{
    int argNumCells;

    (void) randomize();

    if (argc == 2) {
        // Grab argument, convert to integer; init cells with passed arg.
        argNumCells = (int)atoi((char*)argv[1]);
        (void) initializeCells(argNumCells);

        // Display message, showing # of init'ed cells.
        printf("[Game of Life:] Initialized %d Cells.", argNumCells);

        // Wait a second.
        delay(1000);
    }
    // No arguments were passed? Initialize Default # of cells.
    else {
        (void) initializeCells(INIT_CELLS);
        delay(1000);
    }

    // Initialize 0x13H Graphics Mode, 320x200x256
    (void) initgraph();

    // Display program message, copyright etc.
    (void) displayMessage();

    // Draw a border around the cell area.
    (void) drawShadedBorder();

#ifdef __MOUSE_ENABLED
    (void) ShowMouse();
#endif


    // Enter main loop
    while ( !kbhit() )
    {

//////////////////////////////////////////////////////////////////////////////
// From my general feelings I am guessing that opening a bracket in an #ifdef
// expecting to close that bracket if there is a following #ifdef a few lines
// down is somewhat of a different idea.  This technique allows me to let the
// user click per iteration that they want to see.
#ifdef __MOUSE_ENABLED
        (void)ReadMouse();

        if (MOUSE_BUTTON_1_PRESSED) {
#endif
// Display & Process cells, then wait delay time, Reapeat until
// keystroke is enacted.
            (void) displayCells();
            (void) processCells();

#ifdef __MOUSE_ENABLED
            (void) processCells();
        }                           // <-- END funky idea.
#endif

        // @see #define DELAY_TIME
        (void) delay(DELAY_TIME);
    }

#ifdef __MOUSE_ENABLED
    (void) HideMouse();
#endif

    // End graphics mode.
    (void) endgraph();

    // Exit politely.
    return EXIT_SUCCESS;
}