Example #1
1
QgsGrassShell::QgsGrassShell( QgsGrassTools *tools, QTabWidget *parent, const char *name )
    : QFrame( parent ), mTools( tools ), mTabWidget( parent )
{
  Q_UNUSED( name );
  QVBoxLayout *mainLayout = new QVBoxLayout( this );
  QTermWidget *mTerminal = new QTermWidget( 0, this );
  initTerminal( mTerminal );
  QShortcut *pasteShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+V" ) ), mTerminal );
  QShortcut *copyShortcut = new QShortcut( QKeySequence( tr( "Ctrl+Shift+C" ) ), mTerminal );

  mainLayout->addWidget( mTerminal );
  setLayout( mainLayout );

  connect( mTerminal, SIGNAL( finished() ), this, SLOT( closeShell() ) );
  connect( pasteShortcut, SIGNAL( activated() ), mTerminal, SLOT( pasteClipboard() ) );
  connect( copyShortcut, SIGNAL( activated() ), mTerminal, SLOT( copyClipboard() ) );

  // TODO: find a better way to manage the lockfile.
  // Locking should not be done here, a mapset is either locked by GRASS if QGIS is started from GRASS or it is created by QgsGrass::openMapset
  /*
  mLockFilename = QgsGrass::lockFilePath();
  QFile::remove( mLockFilename + ".qgis" );
  if ( !QFile::rename( mLockFilename, mLockFilename + ".qgis" ) )
  {
    QMessageBox::warning( this, tr( "Warning" ), tr( "Cannot rename the lock file %1" ).arg( mLockFilename ) );
  }
  */

  mTerminal->setSize( 80, 25 );
  mTerminal->setColorScheme( COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW );
  mTerminal->startShellProgram();
  mTerminal->setFocus( Qt::MouseFocusReason );
}
Example #2
0
// Main function.
int main(int argc, char** argv) {
  rowIndexNew = 10;
  colIndexNew = 55;
  initTerminal();
  while (true) {
    drawField();
    int key = getch();
    moveTetromino(key);
    showTetromino();
    usleep(1000);
    count++;
    // Arrow up will exit the program
    if (key == 65) {break;}
  }
  endwin();
}
Example #3
0
int main(int argc, char* argv[]) {
    int errLevel;
    dungeon_t dungeon;
    int numMonSpecified = 0;

    //init random
    unsigned int seed;
    seed = (unsigned int)time(NULL); //1453848819;
    srand(seed);
    printf("Seed: %d\n", seed);

    // parse arguments
    int save = 0;
    int load = 0;
    for (int i = 1; i < argc; i++) {
        if (strcmp(argv[i], "--save") == 0) {
            save = 1;
        } else if (strcmp(argv[i], "--load") == 0) {
            load = 1;
        } else if (strcmp(argv[i], "--nummon") == 0) {
            if (i + 1 >= argc) {
                showUsage(argv[0]);
                return 0;
            }
            dungeon.monsterCount = atoi(argv[++i]);
            numMonSpecified = 1;
        } else {
            showUsage(argv[0]);
            return 0;
        }
    }

    if (!numMonSpecified) {
        dungeon.monsterCount = rand() % (42 / 2);
    }

    // load or generate dungeon
    if (load) {
        errLevel = loadDungeon(&dungeon, dungeonFileName());
        if (errLevel) {
            printf("Failed to load the dungeon.  Read error %d\n", errLevel);
            return -1;
        }
        populateRooms(dungeon);
    } else {
        errLevel = generateDungeon(&dungeon);
        if (errLevel) {
            printf("Failed to allocate memory for the dungeon grid.\n");
            return errLevel;
        }
    }
    pathMallocDistGrid(&dungeon.tunnelingDist);
    pathMallocDistGrid(&dungeon.nontunnelingDist);

    // save dungeon
    if (save) {
        errLevel = saveDungeon(dungeon, dungeonFileName());
        if (errLevel) {
            printf("Failed to save the dungeon.  Save error %d\n", errLevel);
            return -1;
        }
    }

    // make calculations
    pathTunneling(&dungeon);
    pathNontunneling(&dungeon);

    // print dungeon
    initTerminal();
    printDungeon(&dungeon);

    // do move
    PC_action userAction = actionMovement;
    while (dungeon.PC.alive && dungeon.monsterCount > 1 && userAction != actionSave) {
        int PCTurn = turnIsPC(&dungeon);
        if (PCTurn) {
            printDungeon(&dungeon);

            userAction = turnDoPC(&dungeon);
            switch (userAction) {
                case actionStairsUp:
                case actionStairsDn:
                    // Destroy old dungeon
                    pathFreeDistGrid(dungeon.nontunnelingDist);
                    pathFreeDistGrid(dungeon.tunnelingDist);
                    destroyDungeon(dungeon);
                    dungeon.monsterCount--; // PC was counted as a "monster".  He must be removed for reinitialisation.
                    // Build new dungeon
                    errLevel = generateDungeon(&dungeon);
                    if (errLevel) {
                        endwin();
                        printf("Failed to allocate memory for the dungeon grid.\n");
                        return errLevel;
                    }
                    pathMallocDistGrid(&dungeon.tunnelingDist);
                    pathMallocDistGrid(&dungeon.nontunnelingDist);
                    pathTunneling(&dungeon);
                    pathNontunneling(&dungeon);
                    break;
                case actionListMonsters:
                    monsterList(&dungeon);
                    break;
                default: break;
            }
        } else {
            turnDo(&dungeon);
        }
    }

    screenClearRow(0);
    if (userAction == actionSave) {
        mvprintw(0, 0, "Game saved (haha, not really!).  Press any key to exit.");
    } else if (!dungeon.PC.alive) {
        mvprintw(0, 0, "You died!  Press any key to exit.");
    } else {
        mvprintw(0, 0, "Yay!  You defeated all the monsters.  Press any key to exit.");
    }

    // Clean up
    getch(); // "press any key"
    endwin();
    pathFreeDistGrid(dungeon.nontunnelingDist);
    pathFreeDistGrid(dungeon.tunnelingDist);
    destroyDungeon(dungeon);
    return 0;
}