void GameDB::update(Reference<Game> gameRef, const Game& newGame) { auto oldGame = *read(gameRef); DataStore::update(gameRef, newGame); // Remove our indexing of the old game auto teams = getTeams(oldGame); deleteGame(teamToGames[teams.first], teams.second, gameRef); deleteGame(teamToGames[teams.second], teams.first, gameRef); // Add indexing of the new game teams = getTeams(newGame); insertSingleGameEntry(teams.first, teams.second, gameRef); insertSingleGameEntry(teams.second, teams.first, gameRef); }
mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::mainWindow) { //#ifndef WIN32 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); //#endif ui->setupUi(this); setupDataBase(); setupTable(); setupComboBox(); ui->mainToolBar->addAction(ui->actionAjouter_console); ui->mainToolBar->addAction(ui->actionEditer_ligne); ui->mainToolBar->addAction(ui->actionSupprimer_ligne); connect(ui->buttonAdd, SIGNAL(clicked()), this, SLOT(addGame())); connect(ui->actionAjouter_console, SIGNAL(triggered()), this, SLOT(addConsole())); connect(ui->actionSupprimer_ligne, SIGNAL(triggered()), this, SLOT(deleteGame())); connect(ui->actionEditer_ligne, SIGNAL(triggered()), this, SLOT(editGame())); connect(ui->actionExporter_en_csv, SIGNAL(triggered()), this, SLOT(exportCSV())); connect(ui->actionImporter_un_CSV, SIGNAL(triggered()), this, SLOT(importCSV())); }
int upx::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: addHostGroup(); break; case 1: updateHostGroup(); break; case 2: delHostGroup(); break; case 3: addHost(); break; case 4: delHost(); break; case 5: groupClicked((*reinterpret_cast< QListWidgetItem*(*)>(_a[1]))); break; case 6: saveSettings(); break; case 7: saveLog2File(); break; case 8: addGame(); break; case 9: updateGame(); break; case 10: deleteGame(); break; case 11: calcGigest(); break; case 12: gameRefresh(); break; case 13: addGameHost(); break; case 14: deleteGameHost(); break; case 15: gameStop(); break; case 16: gameStart(); break; case 17: diffGameFiles(); break; case 18: syncGameFiles(); break; case 19: selectGamePath(); break; case 20: selectGameItem(); break; default: ; } _id -= 21; } return _id; }
void saveGame(string sav = savename) { if(!P.arms) { deleteGame(); return; } savefile = fopen(sav.c_str(), "wb"); error = !savefile; if(error) return; P.saveformat = SAVEFORMAT; P.version = VERSION; stats.whistSize = size(pinfo.whist); P.stairqueue = size(stairqueue); save(P); save(stats); save(playerpos); save(topx); save(topy); saveString(pinfo.charname); saveString(pinfo.username); if(P.twinsNamed) saveString(pinfo.twin[0]), saveString(pinfo.twin[1]); int set = 0; for(int i=0; i<MAXARMS; i++) if(wpn[i]) set |= (1<<i); save(set); for(int i=0; i<MAXARMS; i++) if(wpn[i]) wpn[i]->csave(); if(true) { int trollsize = size(pinfo.trollwpn); save(trollsize); for(int i=0; i<trollsize; i++) save(pinfo.trollkey[i]); for(int i=0; i<trollsize; i++) pinfo.trollwpn[i]->csave(); } for(int i=0; i<P.stairqueue; i++) stairqueue[i]->csave(); for(int i=0; i<stats.whistSize; i++) save(pinfo.whistAt[i]), pinfo.whist[i]->csave(); for(int y=0; y<SY; y++) for(int x=0; x<SX; x++) { cell& c(M.m[y][x]); #define ITEMMASK (1<<24) if(c.it) c.mushrooms |= ITEMMASK; save(c.type), save(c.mushrooms), save(c.dead), save(c.explored); if(c.it) c.it->csave(); c.mushrooms &= ~ITEMMASK; } int32_t i = hydras.size(); save(i); for(int i=0; i<size(hydras); i++) hydras[i]->csave(); fclose(savefile); }
int main(void) { int running = 1; State currState = MainMenu; Game* game = NULL; #ifdef DEBUG game = createGame(); printf("---------------- Open the game successfully \n"); if (!game->setting->useAI) selectOpponent(game); printf("---------------- Changing the game to AI mode \n"); printf("---------------- Going to run 100 times AI vs AI \n"); printf(" Press enter to continue \n"); getchar(); fflush(stdin); while (game->turn < 100) { onAIsTurn(game); } printf("---------------- AI and check is tested \n"); saveLog(game, "log.txt"); printf("---------------- Save record successfully \n"); printf(" Press enter to continue \n"); getchar(); replay(game); printf("---------------- Replay successfully \n"); printf(" Press enter to exit \n"); getchar(); deleteGame(game); printf("---------------- Delete the game successfully \n"); exit(0); #endif game = createGame(); while (running) { switch(currState) { case MainMenu: /*printf("currState = MainMenu\n");*/ currState = onMainMenu(game); break; case NewGame: /*printf("currState = NewGame\n");*/ currState = onNewGame(game); break; case GameMenu: /*printf("currState = GameMenu\n");*/ currState = onGameMain(game); break; case TurnPlayer: /*printf("currState = Player's Turn\n");*/ currState = onPlayersTurn(game); break; case TurnAI: /*printf("currState = AI's Turn\n");*/ currState = onAIsTurn(game); break; case Exit: /*printf("currState = Exit\n");*/ running = 0; break; default: break; } } deleteGame(game); return 0; /* added by Cesar on 1/27 */ }
void loadGame(string sav = savename) { gameExists = false; savefile = fopen(sav.c_str(), "rb"); if(!savefile) { error = true; return; } error = false; load(P); if(P.saveformat < 103) { printf("Savefile format incompatible\n"); return; } loadStats(stats, P.saveformat); if(P.geometry == 0) P.geometry = 8; setDirs(); load(playerpos); load(topx); load(topy); pinfo.charname = loadString(); pinfo.username = loadString(); if(P.twinsNamed) pinfo.twin[0] = loadString(), pinfo.twin[1] = loadString(); if(P.version != VERSION) P.vchanged = true; int set; load(set); for(int i=0; i<MAXARMS; i++) if((set>>i) & 1) wpn[i] = (weapon*) loadS(); if(P.race == R_TROLL || (P.version >= 1030)) { int trollsize; load(trollsize); pinfo.trollwpn.clear(); pinfo.trollkey.resize(trollsize); for(int i=0; i<trollsize; i++) load(pinfo.trollkey[i]); for(int i=0; i<trollsize; i++) pinfo.trollwpn.push_back((weapon*) loadS());; } for(int i=0; i<P.stairqueue; i++) stairqueue.push_back((hydra*) loadS()); pinfo.whistAt.resize(stats.whistSize); for(int i=0; i<stats.whistSize; i++) load(pinfo.whistAt[i]), pinfo.whist.push_back((weapon*) loadS()); for(int y=0; y<SY; y++) for(int x=0; x<SX; x++) { cell& c(M.m[y][x]); c.it = NULL; load(c.type), load(c.mushrooms), load(c.dead), load(c.explored); if(c.mushrooms & ITEMMASK) { c.mushrooms &= ~ITEMMASK; c.it = loadS(); } if(c.type == CT_STAIRUP) stairpos = vec2(x,y); } M.out.clear(); M.out.type = CT_WALL; int32_t i; load(i); hydras.resize(i); for(int i=0; i<size(hydras); i++) { hydra *h = (hydra*) loadS(); hydras[i] = h; M[h->pos].h = h; if(h->color == HC_TWIN) twin = h; } char x; if(error || fread(&x, 1, 1, savefile) != 0) error = true; fclose(savefile); stats.savecount++; if(error) { printf("Error while loading savegame - file deleted\n"); deleteGame(); exit(0); } else gameExists = true; }