void Recorder::set_pos(int pos) { if ( pos > 0 && pos < (int)_cur_path->state_list.size() ) { //setting pos enables play all frames _play_all_frames = true; if ( _sync ) { if ( pos > _path_pos) { target_frame() = pos ; _play_on = true; _paused = false; } else if ( pos < _path_pos ) { target_frame() = pos ; replay(); _paused = false; } } else { _target_frame = pos; _path_pos = pos; _play_on = true; _paused = false; } } }
int main() { unsigned short int corners[4] = {0,2,6,8}; unsigned short int sides[4] = {1,3,5,7}; unsigned short int center = 4; // Pointer for tictactoe structure ticTacToeBoard *selector = malloc(sizeof(*selector)); unsigned short int* intPtr = (unsigned short int*) (selector+5); char *charPtr = (char*) selector; *intPtr = 1; while(*intPtr) { // Set up game setUpGame(selector, charPtr, intPtr); // Run Game runGame(selector, corners, sides, center, charPtr, intPtr); // Ask to replay replay(selector, intPtr); } printf(" Thanks for playing!\n"); // Exits program exit(0); }
int main( int argc, char** argv ) { if ( argc != 3 ) { std::cerr << "Usage: extract_syncevents_dump <replay file> <dump file>" << std::endl; return EXIT_FAILURE; } sc::Replay replay( argv[1] ); if ( !replay.isValid() ) { std::cerr << "Replay file does not exists or is invalid." << std::endl; std::cerr << "If you are using libmpq (default) this may randomly happen. "; std::cerr << "Try to install StormLib (http://www.zezula.net/en/mpq/stormlib.html) "; std::cerr << "and use the CMake option -DBUILD_LIBMPQ=OFF" << std::endl; return EXIT_FAILURE; } replay.getSyncEvents().exportDump( argv[2] ); std::cout << "Replay sync events successfully extracted to \"" << argv[2] << "\"." << std::endl; return EXIT_SUCCESS; }
int main() { srand(time(NULL)); win[PLAYERONE] = win[PLAYERTWO] = 0; char grid[ROWS][COLS]; char input; int row = 4; int col = 4; int winning; int which_turn = rand_xoro(); //This is your turn counter, as requested int this_game_player; int player = this_game_player = rand_player(); do { winning = NOTHING; clear_grid(grid); player_prompt(player, which_turn); for(int i=0; !full(grid) && i < 9 && winning == NOTHING; i++) { int result; while ((result = test_input(input, grid, row, col, which_turn)) != 0) { if(result == 1) { printf("Invalid character, 1, 2, or 3 required\n"); read_everything(); } else if(result == 2) { printf("Invalid character, X or O required\n"); read_everything(); } else if(result == 3) { printf(" already taken\n"); read_everything(); } else if(result == 4) { printf("Invalid character\n"); read_everything(); } else if(result == 5) printf("\nNot enough characters!\n"); else if(result == 6) { printf("Invalid row or column selection\n"); read_everything(); } else if(result == 7) { printf("Invalid character selection for your player\n"); //Requested error message for invalid character read_everything(); } player_prompt(player, which_turn); } player = flip(player); which_turn = flip(which_turn); display_grid(grid); winning = test_winnings(grid); if(winning == NOTHING) player_prompt(player, which_turn); else if(winning == XWINS) { printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); inc_wins(this_game_player); } else if(winning == OWINS) { inc_wins(this_game_player); printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); } else if(winning == TIE) printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); } this_game_player = flip(this_game_player); //Alternate players who go first each game. which_turn = rand_xoro(); //Randomize whether X or O comes first next game } while((winning == NOTHING) || (replay() == AGAIN)); }
JNIEXPORT void JNICALL Java_com_syouquan_script_ScriptEngine_nativeEventStartReplay (JNIEnv * env, jobject thiz ) { LOGI("---call native method start replay---"); if (in_replay == 1) { LOGI("is in replaying"); return; } //sleep 1s sleep(1); in_record = 0; if(play_init() != 0) { LOGI("init failed\n"); return; } if(replay(env) != 0) { LOGI("replay failed\n"); return; } }
int main(int argc, char **argv) { Args args(argc, argv, "DRIVER FILE"); std::unique_ptr<DebugReplay> replay(CreateDebugReplay(args)); if (!replay) return EXIT_FAILURE; args.ExpectEnd(); printf("# time wind_bearing (deg) wind_speed (m/s)\n"); Validity last_available; last_available.Clear(); while (replay->Next()) { const auto &basic = replay->Basic(); if (basic.external_wind_available.Modified(last_available)) { last_available = basic.external_wind_available; TCHAR time_buffer[32]; FormatTime(time_buffer, basic.time); _tprintf(_T("%s %d %g\n"), time_buffer, (int)basic.external_wind.bearing.Degrees(), (double)basic.external_wind.norm); } } }
wxString ReplayList::GetScriptFromReplay (const wxString& ReplayPath , const int version) const { wxString script; try { wxFile replay( ReplayPath, wxFile::read ); if ( !replay.IsOpened() ) return script; SEEK( 20 ); int headerSize=0 ; replay.Read( &headerSize, 4); const int seek = 64 + (version < 5 ? 0 : 240); SEEK( seek ); wxFileOffset scriptSize=0; replay.Read( &scriptSize, 4); scriptSize = LSL::Util::Clamp( wxFileOffset(scriptSize), wxFileOffset(0), replay.Length() ); SEEK( headerSize ); std::string script_a(scriptSize,0); replay.Read( &script_a[0], scriptSize ); script = TowxString( script_a ) ;//(script_a,scriptSize); } catch (...) { } return script; }
bool ReplayList::GetReplayInfos(const std::string& ReplayPath, StoredGame& ret) const { const std::string FileName = LSL::Util::AfterLast(ReplayPath, SEP); // strips file path ret.type = StoredGame::REPLAY; ret.Filename = ReplayPath; ret.battle.SetPlayBackFilePath(ReplayPath); ret.SpringVersion = LSL::Util::BeforeLast(LSL::Util::AfterLast(FileName, "_"), "."); ret.MapName = LSL::Util::BeforeLast(FileName, "_"); if (!wxFileExists(TowxString(ReplayPath))) { wxLogWarning(wxString::Format(_T("File %s does not exist!"), ReplayPath.c_str())); MarkBroken(ret); return false; } wxFile replay(TowxString(ReplayPath), wxFile::read); if (!replay.IsOpened()) { wxLogWarning(wxString::Format(_T("Could not open file %s for reading!"), ReplayPath.c_str())); MarkBroken(ret); return false; } if (replay.Length() == 0) { replay.Close(); MarkBroken(ret); return false; } const int replay_version = replayVersion(replay); ret.battle.SetScript(GetScriptFromReplay(replay, replay_version)); if (ret.battle.GetScript().empty()) { wxLogWarning(wxString::Format(_T("File %s have incompatible version!"), ReplayPath.c_str())); MarkBroken(ret); return false; } GetHeaderInfo(replay, ret, replay_version); ret.battle.GetBattleFromScript(false); ret.ModName = ret.battle.GetHostModName(); ret.battle.SetBattleType(BT_Replay); ret.battle.SetEngineName("spring"); ret.battle.SetEngineVersion(ret.SpringVersion); ret.battle.SetPlayBackFilePath(ReplayPath); //getting this from filename seems more reliable than from demoheader wxDateTime rdate; if (rdate.ParseFormat(TowxString(FileName), _T("%Y%m%d_%H%M%S")) == 0) { wxLogWarning(wxString::Format(_T("Name of the file %s could not be parsed!"), ReplayPath.c_str())); MarkBroken(ret); return false; } ret.date = rdate.GetTicks(); // now it is sorted properly ret.date_string = STD_STRING(rdate.FormatISODate() + _T(" ") + rdate.FormatISOTime()); return true; }
int replayVersion( const wxString& ReplayPath ) { wxFile replay( ReplayPath, wxFile::read ); if ( !replay.IsOpened() ) return 0; SEEK( 16 ); int version = 0; replay.Read( &version, 4); return version; }
InputEventRecorder::InputEventRecorder(QObject *obj): m_Obj(obj), m_InReplay(false), m_Timer(new QTimer), m_uniqueId(0) { m_Timer->setSingleShot(true); QObject::connect(m_Timer, SIGNAL(timeout()), this, SLOT(replay())); }
void Recorder::set_sync(bool s) { //accessor for the ui if ( s && !_sync ) { _target_frame = _path_pos; replay(); } else if ( !s && _sync ) { _path_time = _cur_path->state_list[_path_pos]->t(); } _sync = s; }
int main(void) { if(init() != 0) { printf("init failed\n"); return 1; } if(replay() != 0) { printf("replay failed\n"); return 2; } }
void gameOver(void) { GotoMap(MAP_WIDTH / 4, MAP_HEIGHT / 2 -1); setTextColor(YELLOW); S= snakeLength - SNAKE_MIN_LEN; printf("Game Over! Score: %d.\n", (250-ms)/50*S); GotoMap(MAP_WIDTH / 4, MAP_HEIGHT / 2); printf("按F1输入姓名"); GotoMap(MAP_WIDTH / 4, MAP_HEIGHT / 2+1); printf("Click Enter to retry!"); ch1 = jkGetKey(); if(ch1 == JK_ENTER){replay();}else if(ch1 == JK_F1){db_in(S);}else if(ch1 == JK_ESC){}else{gameOver();} }
void gfxresult_record_replay(gfxresult_t*result, gfxdevice_t*device, gfxfontlist_t**fontlist) { internal_result_t*i = (internal_result_t*)result->internal; reader_t r; if(i->use_tempfile) { reader_init_filereader2(&r, i->filename); } else { reader_init_memreader(&r, i->data, i->length); } replay(0, device, &r, fontlist); }
void replay(Game& game) { std::string rep; if (game.launch()) { std::cout << "Your score : " << game.score() << " (Total : " << game.total_score() << ')' << std::endl << "Do you want to replay ? (y/ *) "; std::getline(std::cin, rep); if (rep == "y" || rep == "Y") return replay(game); } return ; }
int main(int argc, char **argv) { Args args(argc, argv, "DRIVER FILE"); std::unique_ptr<DebugReplay> replay(CreateDebugReplay(args)); if (!replay) return EXIT_FAILURE; args.ExpectEnd(); printf("# time quality wind_bearing (deg) wind_speed (m/s)\n"); CirclingSettings circling_settings; circling_settings.SetDefaults(); CirclingComputer circling_computer; CirclingWind circling_wind; while (replay->Next()) { const bool last_circling = replay->Calculated().circling; circling_computer.TurnRate(replay->SetCalculated(), replay->Basic(), replay->Calculated().flight); circling_computer.Turning(replay->SetCalculated(), replay->Basic(), replay->Calculated().flight, circling_settings); if (replay->Calculated().circling != last_circling) circling_wind.NewFlightMode(replay->Calculated()); CirclingWind::Result result = circling_wind.NewSample(replay->Basic()); if (result.quality > 0) { fixed mag = result.wind.Magnitude(); Angle bearing; if (result.wind.y == fixed(0) && result.wind.x == fixed(0)) bearing = Angle::Zero(); else bearing = Angle::FromXY(result.wind.x, result.wind.y).AsBearing(); TCHAR time_buffer[32]; FormatTime(time_buffer, replay->Basic().time); _tprintf(_T("%s %d %d %g\n"), time_buffer, result.quality, (int)bearing.Degrees(), (double)mag); } } }
void SenderImpl::init(qpid::client::AsyncSession s, AddressResolution& resolver) { session = s; if (state == UNRESOLVED) { sink = resolver.resolveSink(session, address); state = ACTIVE; } if (state == CANCELLED) { sink->cancel(session, name); parent.senderCancelled(name); } else { sink->declare(session, name); replay(); } }
void gfxdevice_record_show(gfxdevice_t*dev) { internal_t*i = (internal_t*)dev->internal; writer_t w; int len; void*data = writer_growmemwrite_memptr(&i->w, &len); gfxdevice_t out; gfxdevice_dummy_init(&out, NULL); reader_t r; reader_init_memreader(&r, data, len); replay(dev, &out, &r, NULL); }
void run() override { try { replay(); } catch (const Poco::Exception &e) { std::cout << "Error: " << e.name() << ' ' << e.message() << std::endl; } catch (const std::exception &e) { std::cout << "Error: " << e.what() << std::endl; } }
void db_in(int score) { int res; char* name; MYSQL mysql; mysql_init(&mysql); // 初始化mysql结构 //mysql_real_connect()函数的功能是连接一个MYSql数据库服务器, //MYSQL结构地址是&mysql,host主机名或地址是localhost, //用户名是root,密码是root,数据库是mydb,端口是3306 if (!mysql_real_connect(&mysql, "localhost", "root", "", "snake", 3306, NULL, 0)) { printf("\n数据库连接发生错误!"); } else { printf("\n数据库连接成功!\n"); //插入一条数据到数据库 switch(ms) { case 200:mul=1;break; case 100:mul=2;break; case 50 :mul=4;break; default:break; } ///////////取时间 time ( &rawtime ); timeinfo = localtime ( &rawtime ); name=input_name(); sprintf(sql_insert, "INSERT INTO score(name,score,time) values('%s','%d','%s')",name,mul*score,asctime (timeinfo)); res = mysql_query(&mysql, sql_insert); if(res) { printf("插入数据失败!\n"); }else { printf("成绩输入成功\n"); } } mysql_close(&mysql); // 释放数据库连接 printf("任意键重试!"); fgetchar(); replay(); }
//rewrite metachanges_log func void masterconn_metachanges_log(serventry *eptr,const uint8_t *data,uint32_t length) { char log_data[1000]; char log_str[1000]; uint64_t version; uint32_t size; //FILE *new_fd; uint8_t log_count = 0; uint8_t log_limit; int ret = 0; NOT_USED(length); log_limit = get8bit(&data); if (eptr->logfd == NULL) { eptr->logfd = fopen("changelog.0.mfs","a"); } while(log_count < log_limit) { version = get64bit(&data); size = get32bit(&data); memcpy(log_str,data,size); data = data + size; if (log_str[size - 1] != '\0') { MFSLOG(LOG_NOTICE,"MATOSLA_CHANGELOG - invalide string the last is %c",log_str[size - 1]); } snprintf(log_data,sizeof(log_data),"%"PRIu64": %s\n",version,log_str); if (eptr->logfd) { ret = replay(log_data); if (ret != 0) { MFSLOG(LOG_ERR,"changelog replay failed"); break; //more complicated method to ensure consistency } fprintf(eptr->logfd,"%"PRIu64": %s",version,log_str); fflush(eptr->logfd); log_count++; } else { MFSLOG(LOG_NOTICE,"lost MFS change %"PRIu64": %s",version,log_str); ret = -1; break; } } if (ret == 0) { masterconn_ack_changelog(eptr,0); } else { masterconn_ack_changelog(eptr,1); } }
void Tp1Simulation1::keyPressed(KeyEvent& event) { switch(event.keyCode) { case VK_X : mIsShaderOn = !mIsShaderOn; break; case VK_A : mIsAxisPresent = !mIsAxisPresent; // Toggle Axis Presence break; case VK_R : replay(); break; } OpenGlApplication::keyPressed(event); }
void gfxdevice_record_flush(gfxdevice_t*dev, gfxdevice_t*out, gfxfontlist_t**fontlist) { internal_t*i = (internal_t*)dev->internal; if(out) { if(!i->use_tempfile) { int len=0; void*data = writer_growmemwrite_memptr(&i->w, &len); reader_t r; reader_init_memreader(&r, data, len); replay(dev, out, &r, fontlist); writer_growmemwrite_reset(&i->w); } else { msg("<fatal> Flushing not supported for file based record device"); exit(1); } } }
void SenderImpl::init(qpid::client::AsyncSession s, AddressResolution& resolver) { sys::Mutex::ScopedLock l(lock); session = s; if (state == UNRESOLVED) { sink = resolver.resolveSink(session, address); state = ACTIVE; } if (state == CANCELLED) { sink->cancel(session, name); sys::Mutex::ScopedUnlock u(lock); parent->senderCancelled(name); } else { sink->declare(session, name); replay(l); } }
bool ReplayList::GetReplayInfos(const wxString& ReplayPath, Replay& ret ) const { const wxString FileName = ReplayPath.AfterLast( wxFileName::GetPathSeparator() ); // strips file path ret.Filename = ReplayPath; ret.battle.SetPlayBackFilePath(STD_STRING(ReplayPath)); ret.SpringVersion = FileName.AfterLast(_T('_')).BeforeLast(_T('.')); ret.MapName = FileName.BeforeLast(_T('_')); if (!wxFileExists(ReplayPath)) { return false; } wxFile replay(ReplayPath, wxFile::read ); if (!replay.IsOpened()) { return false; } const int replay_version = replayVersion( replay ); ret.battle.SetScript(STD_STRING(GetScriptFromReplay( replay, replay_version ))); if ( ret.battle.GetScript().empty() ) { return false; } GetHeaderInfo(replay, ret, replay_version ); ret.battle.GetBattleFromScript( false ); ret.ModName = TowxString(ret.battle.GetHostModName()); ret.battle.SetBattleType( BT_Replay ); ret.battle.SetEngineName("spring"); ret.battle.SetEngineVersion(STD_STRING(ret.SpringVersion)); ret.battle.SetPlayBackFilePath(STD_STRING(ReplayPath)); //getting this from filename seems more reliable than from demoheader wxDateTime rdate; if (rdate.ParseFormat(FileName, _T("%Y%m%d_%H%M%S")) == 0) { wxLogError(_T("Parsing %s failed"), FileName.c_str()); return false; } ret.date=rdate.GetTicks(); // now it is sorted properly ret.date_string=rdate.FormatISODate()+_T(" ")+rdate.FormatISOTime(); return true; }
bool YSwapFile::recover() { mRecovering = true; QFile f( mFilename ); if ( f.open( QIODevice::ReadOnly ) ) { QTextStream stream( &f ); while ( !stream.atEnd() ) { QString line = stream.readLine(); QRegExp rx("([0-9]) ([0-9]*) ([0-9]*) ([01]) ([0-9]*) ([0-9]*) ([01])"); bool error = !stream.atEnd(); if ( !error && rx.exactMatch( line ) ) { YBufferOperation::OperationType type = (YBufferOperation::OperationType)rx.cap(1).toInt(); YBound from = YBound(YCursor(rx.cap(2).toInt(),rx.cap(3).toInt()), rx.cap(4) == "0"); YBound to = YBound(YCursor(rx.cap(5).toInt(),rx.cap(6).toInt()), rx.cap(7) == "0"); YRawData data; line = stream.readLine(); while ( !error && line.length() > 0 ) { if ( stream.atEnd() ) { error = true; } else { data << line.mid(1); line = stream.readLine(); } } if ( !error ) { replay(type, YInterval(from, to), data); } } else { error = true; } if ( error ) { dbg() << "Error reading swap file" << endl; } } f.close(); } else { YSession::self()->guiPopupMessage(_( "The swap file could not be opened, there will be no recovering for this file, you might want to check permissions of files." )); mRecovering = false; return false; } mRecovering = false; return true; }
void Music::onTxtMsg(const std::string& text) { if(text=="stop") { stop(); } else if(text=="replay") { replay(); } else if(text=="+") { adjustVolume(+0.1); } else if(text=="-") { adjustVolume(-0.1); } else if(text == "status") { std::ostringstream strs; strs << volume *100; std::string msg = "Dolanik status: <br />"; msg += "Current volume = " + strs.str() + "%<br />"; if(playback) msg += "I'm currently playing song : "+ currentSong->getTitle() + "(Length:" /*"+ Anal::toStr(getCurrentSongLength()) +" */ "s ) <br />"; //FIXME mc->SendTextMessage("music",msg); } else if(text == "playlist") { mc->SendTextMessage("music", genPlaylistString()); } else if(text.substr(0, 2) == "eq") { int band = -1; double amp = -1; if(text.substr(3, 5) == "reset") { resetEqualizer(); return; } std::stringstream ss; ss << text.substr(2); ss >> band; ss >> amp; setEqualizer(band,amp); } else if(text == "help")
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setFixedSize(1280,840); // make/connect a timer to count down timerm = new QTimer(); connect(timerm,SIGNAL(timeout()),this,SLOT(replay())); // start the timer timerm->start(96500); //set bgm bgm = new QMediaPlayer(); bgm->setMedia(QUrl("qrc:/sound/Facebook.wav")); bgm->play(); }
void QDeclarativePinchGenerator::keyPressEvent(QKeyEvent *e) { if (!enabled_) { e->ignore(); } if (e->key() == Qt::Key_C) { clear(); } else if (e->key() == Qt::Key_R) { replay(); } else if (e->key() == Qt::Key_S) { stop(); } else if (e->key() == Qt::Key_Plus) { setReplaySpeedFactor(replaySpeedFactor() + 0.1); } else if (e->key() == Qt::Key_Minus) { setReplaySpeedFactor(replaySpeedFactor() - 0.1); } else { qDebug() << metaObject()->className() << "Unsupported key event."; } }
static void fail() { Ins *i1; int i; printf("\nIn registers: "); for (i=0; i<mbeg.n; i++) printf("%s(r%d) ", tmp[mbeg.t[i]].name, mbeg.r[i]); printf("\n"); printf("Parallel move:\n"); for (i1=ins; i1<ip; i1++) printf("\t %s <- r%d\n", tmp[i1->to.val].name, i1->arg[0].val); replay(); abort(); }