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(); }
Palapeli::PuzzleCreatorDialog::PuzzleCreatorDialog() : m_result(0) , m_imageSelector(new KUrlRequester) , m_nameEdit(new KLineEdit) , m_commentEdit(new KLineEdit) , m_authorEdit(new KLineEdit) , m_slicerSelector(new Palapeli::SlicerSelector) , m_slicerConfigMasterWidget(new QStackedWidget) { //setup dialog setCaption(i18nc("@title:window", "Create new puzzle")); showButton(KDialog::Help, false); //setup image selector m_imageSelector->setMode(KFile::File | KFile::LocalOnly | KFile::ExistingOnly); //build sublayouts QFormLayout* sourceLayout = new QFormLayout; sourceLayout->addRow(i18nc("@label:chooser", "Image file:"), m_imageSelector); sourceLayout->addRow(new QLabel(i18nc("@info", "Please describe below the image which you have chosen."))); sourceLayout->addRow(i18nc("@label:textbox", "Image name:"), m_nameEdit); sourceLayout->addRow(i18nc("@label:textbox (like in: This comment is optional.)", "Optional comment:"), m_commentEdit); sourceLayout->addRow(i18nc("@label:textbox", "Name of image author:"), m_authorEdit); foreach (const Pala::Slicer* slicer, m_slicerSelector->slicers()) { m_slicerConfigWidgets[slicer] = new Palapeli::SlicerConfigWidget(slicer); m_slicerConfigMasterWidget->addWidget(m_slicerConfigWidgets[slicer]); } //build page widget items m_sourcePage = addPage(new QWidget, i18nc("@item:inlistbox (page name in an assistant dialog)", "Choose image")); m_sourcePage->setHeader(i18nc("@title:tab (page header in an assistant dialog)", "Specify the source image to be sliced into pieces")); m_sourcePage->widget()->setLayout(sourceLayout); m_slicerPage = addPage(m_slicerSelector, i18nc("@item:inlistbox (page name in an assistant dialog)", "Choose slicer")); m_slicerPage->setHeader(i18nc("@title:tab (page header in an assistant dialog)", "Choose a slicing method")); m_slicerConfigPage = addPage(m_slicerConfigMasterWidget, i18nc("@item:inlistbox (page name in an assistant dialog)", "Configure slicer")); m_slicerConfigPage->setHeader(i18nc("@title:tab (page header in an assistant dialog)", "Tweak the parameters of the chosen slicing method")); //wire up stuff connect(this, SIGNAL(accepted()), this, SLOT(createPuzzle())); connect(m_imageSelector, SIGNAL(urlSelected(KUrl)), this, SLOT(checkData())); connect(m_nameEdit, SIGNAL(textChanged(QString)), this, SLOT(checkData())); connect(m_authorEdit, SIGNAL(textChanged(QString)), this, SLOT(checkData())); checkData(); //to invalidate first page connect(m_slicerSelector, SIGNAL(currentSelectionChanged(Palapeli::SlicerSelection)), this, SLOT(updateSlicerSelection(Palapeli::SlicerSelection))); }
//---------------------------------------------------------------------- void game::guiInput(int in){ //any gui input resets reset timer //start timer to go back to inactive state if(step != -1){ goToAttractStepI = ofGetElapsedTimef(); } if(in == 'b'){ ofToggleFullscreen(); } ////// if(step == -1){ //on attract / inactive state step = 0; goToAttractStepI = ofGetElapsedTimef(); } ////////////////////////////////////////////step 0 inputs ////////////////////////////////////////////step 0 inputs ////////////////////////////////////////////step 0 inputs else if(step == 0){ //waiting for an object to be selected //it cam be from the shapes on the center // or from the object menu on the side //////////////////////////////////////////////////////// //////////////////object menu on the side //waiting for shape to be selected if(in == '1') { //load object recieves (object id, boolean position, display position) loadObject(1,slicingPos,posP); } if(in == '2') { loadObject(2,slicingPos,posP); } if(in == '3') { loadObject(3,slicingPos,posP); } if(in == '4') { loadObject(4,slicingPos,posP); } if(in == '5') { loadObject(5,slicingPos,posP); } if(in == '6') { loadObject(6,slicingPos,posP); } if(in == '7') { loadObject(7,slicingPos,posP); } //if(in == '8') { // loadObject(8,objectPos,posP); //} if(in == '9') { prepareDrawing(); } } ////////////////////////////////////////////step 1 inputs ////////////////////////////////////////////step 1 inputs ////////////////////////////////////////////step 1 inputs else if(step == 1){ //is showing object with flat color //selected an object if(in == 'n') { //go to step 2 setCurrentStep(2); //show armature } else{ //waiting for shape to be selected if(in == '1') { //user can change the selected object clearDisplayedObject(); //load object recieves (object id, boolean position, display position) loadObject(1,slicingPos,posP); //pos.z its the torus radious } if(in == '2') { clearDisplayedObject(); loadObject(2,slicingPos,posP); } if(in == '3') { clearDisplayedObject(); loadObject(3,slicingPos,posP); } if(in == '4') { clearDisplayedObject(); loadObject(4,slicingPos,posP); } if(in == '5') { clearDisplayedObject(); loadObject(5,slicingPos,posP); } if(in == '6') { //user can change the selected object clearDisplayedObject(); loadObject(6,slicingPos,posP); } if(in == '7') { //user can change the selected object clearDisplayedObject(); loadObject(7,slicingPos,posP); } /*if(in == '8') { loadObject(8,objectPos,posP); }*/ if(in == '9') { clearDisplayedObject(); prepareDrawing(); } } } ////////////////////////////////////////////step 2 inputs ////////////////////////////////////////////step 2 inputs ////////////////////////////////////////////step 2 inputs else if(step == 2){ //waiting for armature to be selected if(in == '1') { //select armature 1 loadArmature(1); } if(in == '2') { //select armature 2 loadArmature(2); } } ////////////////////////////////////////////step 3 inputs ////////////////////////////////////////////step 3 inputs ////////////////////////////////////////////step 3 inputs else if(step == 3){ //armature was selected ////showing armature another armature can be selected if(in == '1') { //select armature 1 loadArmature(1); } if(in == '2') { //select armature 2 loadArmature(2); } //////////////////////////////move all armature if(in == 'l') { ofVec3f p = ofVec3f (5,0,0); moveA(p); } if(in == 'j') { ofVec3f p = ofVec3f (-5,0,0); moveA(p); } if(in == 'i') { ofVec3f p = ofVec3f (0,-5,0); moveA(p); } if(in == 'k') { ofVec3f p = ofVec3f (0,5,0); moveA(p); } ///z movement if(in == 'o') { ofVec3f p = ofVec3f (0,0,5); moveA(p); } if(in == 'p') { ofVec3f p = ofVec3f (0,0,-5); moveA(p); }//////////////////////////////rotate all armature if(in == 'c') {//rotate around y ofVec3f r = ofVec3f (0,5,0); rotateA(r); } if(in == 'x') {//rotate around y ofVec3f r = ofVec3f (0,-5,0); rotateA(r); } if(in == 'w') {//rotate around x ofVec3f r = ofVec3f (5,0,0); //degrees!!! rotateA(r); } if(in == 's') {//rotate around x ofVec3f r = ofVec3f (-5,0,0); rotateA(r); } if(in == 'e') {//rotate around z ofVec3f r = ofVec3f (0,0,5); //degrees!!! rotateA(r); } if(in == 'd') {//rotate around z ofVec3f r = ofVec3f (0,0,-5); rotateA(r); } /////////////////a puzzle can be made if(in == 'n') { //send the armature rotations to the 3dObject applyArmRotations(); //now we know the offset position from the armature to create-> cutter & slicer createCutterSlicer(); //do slicing createPuzzle(posP);//create Puzzle goes to step 4 to show the puzzle } } ////////////////////////////////////////////step 4 inputs ////////////////////////////////////////////step 4 inputs ////////////////////////////////////////////step 4 inputs else if(step == 4){ //showing puzzle with colors //waiting for color change if(in == '1') { //call color change funtion ofFloatColor sc = ofFloatColor (1, 1, 0); //yellow ofFloatColor menuColor = ofFloatColor (1, 0, 1); //this color comes from the GUI changeColorToColor(sc,menuColor); } //pressed NEXT if(in == 'n') { //go to step 5 setCurrentStep(5); } ///////////////////////////////move all puzzle if(in == 'l') { SG_VECTOR p = {10,0,0}; moveP(p); } if(in == 'j') { SG_VECTOR p = {-10,0,0}; moveP(p); } if(in == 'i') { SG_VECTOR p = {0,-10,0}; moveP(p); } if(in == 'k') { SG_VECTOR p = {0,10,0}; moveP(p); } /////////////rotate all puzzle // two finger swipe gesture //if(in == 'm') {//rotate right // SG_VECTOR r = {0,10,0};//{0,0.1,0}; // rotateP(r); //} //if(in == 'n') {//rotate left // SG_VECTOR r = {0,-10,0};//{0,-0.1,0}; // rotateP(r); //} //if(in == 'y') {//rotate up // SG_VECTOR r = {10,0,0};// {0.1,0,0}; // rotateP(r); //} //if(in == 'h') {//rotate down // SG_VECTOR r = {-10,0,0};//{-0.1,0,0}; // ofVec3f v; // rotateP(r); //} } ////////////////////////////////////////////step 5 inputs ////////////////////////////////////////////step 5 inputs ////////////////////////////////////////////step 5 inputs else if(step == 5){ //selected color (or not, its not mandatory) //pressed next on color palette step //showing puzzle //now the puzzle can be played with int randcubie=13;//rand()%26;//to follow this cubie for now //this will be decided upon touch, or click on top of puzzle if(myPuzzle->isMoving() == false){ //this is to prevent from reading events while puzzle is moving if(in == 'u'){ //undo last move unDo(); } ////////////////////////////////////////////// FACE ROTATIONS ////////////////////////////// if(in == 'z') { //do rotationbased ontwo cubies id int cubieA = 11; int cubieB = 10; rotateTwoIds(cubieA,cubieB,true); } ////////////////////////////////////////////// FACE ROTATIONS ////////////////////////////// //////// x axis //// x axis if(in == 'q') { //clockwise SG_VECTOR axis = {1,0,0}; rotateByIDandAxis(randcubie,axis,true); } if(in == 'a') { //counter clockwise SG_VECTOR axis = {1,0,0}; rotateByIDandAxis(randcubie,axis,false); } //////// y axis //// y axis if(in == 'w') { //clockwise SG_VECTOR axis = {0,1,0}; rotateByIDandAxis(randcubie,axis,true); }if(in == 's') { //counter clockwise SG_VECTOR axis = {0,1,0}; rotateByIDandAxis(randcubie,axis,false); } //////// z axis //// z axis if(in == 'e') { //clockwise SG_VECTOR axis = {0,0,1}; rotateByIDandAxis(randcubie,axis,true); }if(in == 'd') { //counter clockwise SG_VECTOR axis = {0,0,1}; rotateByIDandAxis(randcubie,axis,false); } } ////////////////////////////////////move all puzzle if(in == 'l') { SG_VECTOR p = {10,0,0}; moveP(p); } if(in == 'j') { SG_VECTOR p = {-10,0,0}; moveP(p); } if(in == 'i') { SG_VECTOR p = {0,-10,0}; moveP(p); } if(in == 'k') { SG_VECTOR p = {0,10,0}; moveP(p); } /////////////rotate all puzzle // two finger swipe gesture //if(in == 'm') {//rotate right // SG_VECTOR r = {0,2,0};//{0,0.1,0}; // rotateP(r); //} //if(in == 'n') {//rotate left // SG_VECTOR r = {0,-2,0};//{0,-0.1,0}; // rotateP(r); //} //if(in == 'y') {//rotate up // SG_VECTOR r = {2,0,0};// {0.1,0,0}; // rotateP(r); //} //if(in == 'h') {//rotate down // SG_VECTOR r = {-2,0,0};//{-0.1,0,0}; // ofVec3f v; // rotateP(r); //} //if(in == 'o') {//rotate c // SG_VECTOR r = {0,0,-2};// {0.1,0,0}; // rotateP(r); //} //if(in == 'p') {//rotate cc // SG_VECTOR r = {0,0,2};//{-0.1,0,0}; // ofVec3f v; // rotateP(r); //} }else if(step == 6){ ////////////////////////////extrusion if(in == 'e') { //take drawing data //check for existing drawing if(myCanvas->drawingExists()){ //make extruded object if(extrudeObject(myCanvas->getPolyline())){ }else{ prepareDrawing(); } } }else if(in == 's'){ ofPolyline *draw = new ofPolyline(); //star draw->addVertex(ofVec2f(-5,-210)); draw->addVertex(ofVec2f(60,-60)); draw->addVertex(ofVec2f(210,-45)); draw->addVertex(ofVec2f(105,60)); draw->addVertex(ofVec2f(150,210)); draw->addVertex(ofVec2f(-5,135)); draw->addVertex(ofVec2f(-150,210)); draw->addVertex(ofVec2f(-105,60)); draw->addVertex(ofVec2f(-210,-45)); draw->addVertex(ofVec2f(-60,-60)); draw->addVertex(ofVec2f(-5,-210)); //draw->close(); // close the shape extrudeObject(draw); } //////////////////////////////////////////////////////// //////////////////object menu on the side //waiting for shape to be selected else if(in == '1') { clearDisplayedObject(); //load object recieves (object id, boolean position, display position) loadObject(1,slicingPos,posP); } else if(in == '2') { clearDisplayedObject(); loadObject(2,slicingPos,posP); } else if(in == '3') { clearDisplayedObject(); loadObject(3,slicingPos,posP); } else if(in == '4') { clearDisplayedObject(); loadObject(4,slicingPos,posP); } else if(in == '5') { clearDisplayedObject(); loadObject(5,slicingPos,posP); } else if(in == '6') { clearDisplayedObject(); loadObject(6,slicingPos,posP); } else if(in == '7') { clearDisplayedObject(); loadObject(7,slicingPos,posP); } //if(in == '8') { // loadObject(8,objectPos,posP); //} else if(in == '9') { clearDisplayedObject(); prepareDrawing(); } } ///////////////////////////////////////////////////////////////// ////////////////RESART button can work on any step, its not showed on step 1 (object selected) if(in == 'r'){ //tell a game to restart restart(); } }