void SpGameManager::postCommand(Command command) { if (gameOver) { return; } if (command.commandType == Command::CommandType::TileOpen) { auto tileOpenCommand = command.tileOpenCommand; handleReveal(Board::BoardPoint(tileOpenCommand.line, tileOpenCommand.column)); } if (command.commandType == Command::CommandType::TileFlag) { Board::BoardPoint point(command.tileFlagCommand.line, command.tileFlagCommand.column); if (board.isRevealed(point)) { return; } board.toggleFlag(point); postUiEventAction(UiEvent(UiEvent::TileFlagEvent(point.line, point.column, board.isFlagged(point)))); } }
void SpGameManager::handleRevealAround(Board::BoardPoint rootPoint) { int flagsAround = 0; int minesAround = 0; for (int i = 0; i < 8; i++) { auto neighbor = rootPoint.getNeighbor((Direction)i); if (board.isFlagged(neighbor)) { flagsAround++; } if (board.isMine(neighbor)) { minesAround++; } } if (flagsAround != minesAround) { return; } for (int i = 0; i < 8; i++) { auto neighbor = rootPoint.getNeighbor((Direction)i); if (board.isValid(neighbor) && !board.isRevealed(neighbor) && !board.isFlagged(neighbor)) { handleReveal(neighbor); } } }
void Helper::readCommand() { QString command = readLine(); if( input.atEnd()) { #ifdef DEBUG_KDE QTextStream( stderr ) << "EOF, existing." << endl; #endif QCoreApplication::exit(); return; } #ifdef DEBUG_KDE QTextStream( stderr ) << "COMMAND:" << command << endl; #endif bool status; if( command == "CHECK" ) status = handleCheck(); else if( command == "GETPROXY" ) status = handleGetProxy(); else if( command == "HANDLEREXISTS" ) status = handleHandlerExists(); else if( command == "GETFROMEXTENSION" ) status = handleGetFromExtension(); else if( command == "GETFROMTYPE" ) status = handleGetFromType(); else if( command == "GETAPPDESCFORSCHEME" ) status = handleGetAppDescForScheme(); else if( command == "APPSDIALOG" ) status = handleAppsDialog(); else if( command == "GETOPENFILENAME" ) status = handleGetOpenX( false ); else if( command == "GETOPENURL" ) status = handleGetOpenX( true ); else if( command == "GETSAVEFILENAME" ) status = handleGetSaveX( false ); else if( command == "GETSAVEURL" ) status = handleGetSaveX( true ); else if( command == "GETDIRECTORYFILENAME" ) status = handleGetDirectoryX( false ); else if( command == "GETDIRECTORYURL" ) status = handleGetDirectoryX( true ); else if( command == "OPEN" ) status = handleOpen(); else if( command == "REVEAL" ) status = handleReveal(); else if( command == "RUN" ) status = handleRun(); else if( command == "GETDEFAULTFEEDREADER" ) status = handleGetDefaultFeedReader(); else if( command == "OPENMAIL" ) status = handleOpenMail(); else if( command == "OPENNEWS" ) status = handleOpenNews(); else if( command == "ISDEFAULTBROWSER" ) status = handleIsDefaultBrowser(); else if( command == "SETDEFAULTBROWSER" ) status = handleSetDefaultBrowser(); else if( command == "DOWNLOADFINISHED" ) status = handleDownloadFinished(); else { QTextStream( stderr ) << "Unknown command for KDE helper: " << command << endl; status = false; } // status done as \1 (==ok) and \0 (==not ok), because otherwise this cannot happen // in normal data (\ is escaped otherwise) outputLine( status ? "\\1" : "\\0", false ); // do not escape }