Beispiel #1
0
//This function sets the new dimentions of the puzzle and re-shuffles it.
void Puzzle::setDimensions( int newWidth, int newHeight) {
    width = newWidth ;
    height = newHeight ;  //It's not a square, so each dimention must be named
    turns = 0 ;
    do { //initialize it and shuffle it again until you come across a solvable one
        initPuzzle() ;
        shufflePuzzle() ;
        
        //cout << "Shuffled puzzle: \n";
        //output(cout);                             }this was used in debugging, but is no longer needed
        //system("PAUSE");
        
    } while ( !isSolvable() ) ;  //do it until it's solved
}
Beispiel #2
0
void interfaceLoop() {
    Puzzle *puzzle = NULL;
    char command = '\0';
    
    showSolution = false;
    
    createDirectionKeys();
    createOptionKeys();
    
    do {
        puzzle = createPuzzle(getPuzzleSize());
        shuffleCount = getShuffleCount();
        shufflePuzzle(puzzle, shuffleCount);
        
        showSolution = false;
        
        while( !isSolved(puzzle) ){
            printHeader();
            printPuzzle(puzzle);
            command = getNextCommand(puzzle);
            
            if(command == INVERT_KEY) {
                puzzle->inverted = (puzzle->inverted) ? false : true;
                invertSolution(puzzle);
                setDirectionVectors(puzzle);
            }
            else if(command == SOLVE_KEY)
                showSolution = (showSolution) ? false : true;
            else if(command == QUIT_KEY || command == RESTART_KEY)
                break;
            else
                applyDirection(puzzle, getData(directionKeys, command));
        }
        
        if( isSolved(puzzle) ) {
            printPuzzle(puzzle);
            printWinner();
        }
        
        destroyPuzzle(&puzzle);
    } while(command == RESTART_KEY);
    
    destroyOptionKeys();
    destroyDirectionKeys();
}