EvidenceHunt.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. #include <QTime>
  2. #include <QTimer>
  3. #include <QtXml/QDomDocument>
  4. #include <QtXml/QDomNode>
  5. //#include <Phonon>
  6. using namespace std;
  7. #include <cstdlib>
  8. #include <QDebug>
  9. #include "EvidenceHuntGame.h"
  10. void tilesPropAppend(QDeclarativeListProperty<TileData>* prop, TileData* value) {
  11. Q_UNUSED(prop);
  12. Q_UNUSED(value);
  13. return; //Append not supported
  14. }
  15. int tilesPropCount(QDeclarativeListProperty<TileData>* prop) {
  16. return static_cast<QList<TileData*>*>(prop->data)->count();
  17. }
  18. TileData* tilesPropAt(QDeclarativeListProperty<TileData>* prop, int index) {
  19. return static_cast<QList<TileData*>*>(prop->data)->at(index);
  20. }
  21. QDeclarativeListProperty<TileData> EvidencehuntGame::tiles() {
  22. return QDeclarativeListProperty<TileData>(this, &_tiles, &tilesPropAppend, &tilesPropCount, &tilesPropAt, 0);
  23. }
  24. void suspectsPropAppend(QDeclarativeListProperty<SuspectData>* prop, SuspectData* value) {
  25. Q_UNUSED(prop);
  26. Q_UNUSED(value);
  27. return;
  28. }
  29. int suspectsPropCount(QDeclarativeListProperty<SuspectData>* prop) {
  30. return static_cast<QList<SuspectData*>*>(prop->data)->count();
  31. }
  32. SuspectData* suspectsPropAt(QDeclarativeListProperty<SuspectData>* prop, int index) {
  33. return static_cast<QList<SuspectData*>*>(prop->data)->at(index);
  34. }
  35. QDeclarativeListProperty<SuspectData> EvidencehuntGame::suspects(){
  36. return QDeclarativeListProperty<SuspectData>(this, &_suspects, &suspectsPropAppend, &suspectsPropCount, &suspectsPropAt, 0);
  37. }
  38. void playersPropAppend(QDeclarativeListProperty<TopPlayerData>* prop, TopPlayerData* value) {
  39. Q_UNUSED(prop);
  40. Q_UNUSED(value);
  41. return;
  42. }
  43. int playersPropCount(QDeclarativeListProperty<TopPlayerData>* prop) {
  44. return static_cast<QList<TopPlayerData*>*>(prop->data)->count();
  45. }
  46. TopPlayerData* playersPropAt(QDeclarativeListProperty<TopPlayerData>* prop, int index) {
  47. return static_cast<QList<TopPlayerData*>*>(prop->data)->at(index);
  48. }
  49. QDeclarativeListProperty<TopPlayerData> EvidencehuntGame::topPlayers(){
  50. /*
  51. QList< TopPlayerData *>::iterator i;
  52. for (i = _players.begin(); i != _players.end(); ++i) {
  53. TopPlayerData *currentPlayerData = *i;
  54. qDebug() << currentPlayerData->name();
  55. }
  56. */
  57. return QDeclarativeListProperty<TopPlayerData>(this, &_players, &playersPropAppend, &playersPropCount, &playersPropAt, 0);
  58. }
  59. void EvidenceInfo::loadEvidence(TileData *t) {
  60. _title = t->type()->description();
  61. _type = t->type();
  62. _description = t->description();
  63. _image = t->type()->image();
  64. _isVisible = true;
  65. emit evidenceChanged();
  66. }
  67. void EvidenceInfo::loadCustomMessage(QString title, EvidenceType *type, QString message, QString image) {
  68. _title = title;
  69. _type = type;
  70. _description = message;
  71. _image = image;
  72. _isVisible = true;
  73. emit evidenceChanged();
  74. }
  75. EvidencehuntGame::EvidencehuntGame(QApplication *app)
  76. : numCols(8), numRows(8), numSuspects(5), playing(true), won(false), defaultScore(5), scoreMultiplier(1), wonStreak(0), isSolveMode(false)
  77. {
  78. _app = app;
  79. _settings = new QSettings();
  80. _translator = new QTranslator();
  81. _app->installTranslator(_translator);
  82. setObjectName("mainObject");
  83. srand(QTime(0,0,0).secsTo(QTime::currentTime()));
  84. tileTypes << new EvidenceType("grey","#ffffff",0,"empty.png") //0 Blank fields
  85. << new EvidenceType("red","#ff0000",1,"terrible-murder.jpg") //1
  86. << new EvidenceType("red","#ff0000",1,"knife-gun.jpg") //2
  87. << new EvidenceType("blue","#0000ff",8,"evidence-elimination.jpg") //3
  88. << new EvidenceType("green","#00ff00",2,"evidence-incriminating.jpg") //4
  89. << new EvidenceType("purple","#ff00ff",1,"detective-office.jpg") //5
  90. << new EvidenceType("purple","#ff00ff",1,"alibi.jpg") //6
  91. << new EvidenceType("purple","#ff00ff",1,"detective-office.jpg") //7
  92. << new EvidenceType("yellow","#ffff00",10,"evidence-suspect.jpg") //8
  93. << new EvidenceType("purple","#ff00ff",1,"boss.jpg"); //9
  94. loadLanguage();
  95. //initialize array
  96. for(int ii = 0; ii < numRows * numCols; ++ii) {
  97. _tiles << new TileData;
  98. }
  99. for(int ii = 0; ii < numSuspects; ++ii) {
  100. _suspects << new SuspectData();
  101. }
  102. _evidenceInfo = new EvidenceInfo();
  103. connect(_evidenceInfo, SIGNAL(evidenceChanged()), this, SLOT(changeEvidenceInfo()));
  104. _settings->setValue("currentScore", 0);
  105. _scoreboard = new Scoreboard();
  106. connect(_scoreboard, SIGNAL(boardChanged(QList< QHash<QString,QString> >)), this, SLOT(loadScoreboardPlayers(QList< QHash<QString,QString> >)));
  107. connect(_scoreboard, SIGNAL(boardError()), this, SIGNAL(openBoardErrorDialog()));
  108. connect(_scoreboard, SIGNAL(boardSubmitSuccess(int)), this, SLOT(boardSubmitSuccess(int)));
  109. //Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory,
  110. //#if defined(Q_EVHUNT_MEEGO)
  111. //Phonon::MediaSource("/opt/evidencehunt/music/music.mp3"));
  112. //#else
  113. //Phonon::MediaSource("music/music.mp3"));
  114. //#endif
  115. //music->play();
  116. reset();
  117. }
  118. void EvidencehuntGame::loadLanguage() {
  119. if (_settings->value("lang")!="en_US" && _settings->value("lang")!="hu_HU" && _settings->value("lang")!="sr_RS" && _settings->value("lang")!="it_IT") {
  120. _settings->setValue("lang", "en_US");
  121. }
  122. if (!_translator->load("evidencehunt." + _settings->value("lang").toString() + "qm", ":/qml/")) {
  123. _translator->load("evidencehunt." + _settings->value("lang").toString() + "qm", ":/qml/");
  124. }
  125. roleTypes = loadFromXml(":/internationalization/"+_settings->value("lang").toString().left(2)+"/roleTypes.xml");
  126. foreach(SuspectData* s, _suspects) {
  127. s->reloadEvidences();
  128. }
  129. tileTypes[0]->setDescription("");
  130. tileTypes[1]->setDescription(tr("__SHOCKINGMURDER__"));
  131. tileTypes[2]->setDescription(tr("__MURDERWEAPON__"));
  132. tileTypes[3]->setDescription(tr("__ELIMINATIONCLUE__"));
  133. tileTypes[4]->setDescription(tr("__INCRIMINATINGCLUE__"));
  134. tileTypes[5]->setDescription(tr("__HIGHPROFILE__"));
  135. tileTypes[6]->setDescription(tr("__AIRTIGHTALIBI__"));
  136. tileTypes[7]->setDescription(tr("__SEARCHWARRANT__"));
  137. tileTypes[8]->setDescription(tr("__SUSPECTINFO__"));
  138. tileTypes[9]->setDescription(tr("__LARGEREWARD__"));
  139. suspectProperties = loadFromXml(":/internationalization/"+_settings->value("lang").toString().left(2)+"/suspectProperties.xml");
  140. suspectNegativeProperties = loadFromXml(":/internationalization/"+_settings->value("lang").toString().left(2)+"/suspectNegativeProperties.xml");
  141. startScenes = loadFromXml(":/internationalization/"+_settings->value("lang").toString().left(2)+"/startScenes.xml");
  142. refreshLanguage();
  143. emit languageChanged();
  144. }
  145. void EvidencehuntGame::refreshLanguage(bool loadStartScene) {
  146. foreach(SuspectData *s, _suspects) {
  147. s->setRole(s->role(), roleTypes[s->role()]);
  148. }
  149. foreach(TileData* t, _tiles) {
  150. if (t->type()->id()==1) {
  151. t->setDescription(startScenes[startScene]+"\n\n" + tr("__SUSPECTNUMBER__").arg(QString::number(numSuspects))+"!") ;
  152. if (loadStartScene) {
  153. _evidenceInfo->loadEvidence(t);
  154. }
  155. }
  156. if (t->type()->id()==2) {
  157. t->setDescription(tr("__FOUNDMURDERWEAPON__") + ".\n\n" + tr("__YOURREWARD__").arg("50"));
  158. }
  159. if (t->type()->id()==3) {
  160. t->setDescription(tr("__KILLER__") + " " + suspectNegativeProperties[t->propertyId()] + "." );
  161. }
  162. if (t->type()->id()==4) {
  163. t->setDescription(tr("__KILLER__") + " " + suspectProperties[t->propertyId()] + ".");
  164. }
  165. if (t->type()->id()==5) {
  166. t->setDescription(tr("__DOUBLEREWARD__"));
  167. }
  168. if (t->type()->id()==6) {
  169. t->setDescription(tr("__HASALIBI__").arg(_suspects[alibiId]->roleText())+"!");
  170. }
  171. if (t->type()->id()==7) {
  172. t->setDescription(tr("__EXTRATIME__"));
  173. }
  174. if (t->type()->id()==8) {
  175. t->setDescription(_suspects[t->suspectId()]->roleText() + " " + suspectProperties[t->propertyId()]+ ".");
  176. }
  177. if (t->type()->id()==9) {
  178. t->setDescription(tr("__FOUNDLARGEREWARD__")+ "\n\n" + tr("__YOURREWARD__").arg("100"));
  179. }
  180. }
  181. }
  182. QList<QString> EvidencehuntGame::loadFromXml(QString fileString) {
  183. QList<QString> xmlData;
  184. QDomDocument doc("suspectProperties");
  185. QFile file(fileString);
  186. file.open(QIODevice::ReadOnly);
  187. doc.setContent(&file);
  188. file.close();
  189. QDomElement docElem = doc.documentElement();
  190. QDomNode n = docElem.firstChild();
  191. while(!n.isNull()) {
  192. QDomElement e = n.toElement();
  193. if(!e.isNull()) {
  194. xmlData << e.text();
  195. }
  196. n = n.nextSibling();
  197. }
  198. return xmlData;
  199. }
  200. void EvidencehuntGame::setBoard() {
  201. /*
  202. _settings->setValue("lastScore", 0);
  203. _settings->setValue("currentScore", 0);
  204. _settings->setValue("maxScore", 0);
  205. _settings->setValue("maxScoreSubmitted", 0);
  206. */
  207. foreach(TileData* t, _tiles) {
  208. t->setHasEvidence(false);
  209. t->setHint(-1);
  210. t->setType(tileTypes[0]);
  211. t->setDescription("");
  212. t->setPropertyId(-1);
  213. //t->flip();
  214. }
  215. QList<int> usedRoles;
  216. QList<int> usedProfiles;
  217. killerId = rand() % numSuspects;
  218. //qDebug() << killerId;
  219. emit killerChanged();
  220. int counter = 0;
  221. foreach(SuspectData* s, _suspects) {
  222. int profileId = rand() % 11;
  223. while (usedProfiles.contains(profileId)) {
  224. profileId = rand() % 11;
  225. }
  226. s->resetEvidences();
  227. s->setProfile(profileId);
  228. usedProfiles << profileId;
  229. int roleId = rand() % roleTypes.count();
  230. while (usedRoles.contains(roleId)) {
  231. roleId = rand() % roleTypes.count();
  232. }
  233. s->setRole(roleId, roleTypes[roleId]);
  234. usedRoles << roleId;
  235. if (counter==killerId) {
  236. s->setIsKiller(true);
  237. } else {
  238. s->setIsKiller(false);
  239. }
  240. counter++;
  241. }
  242. if (!won) {
  243. _settings->setValue("currentScore", 0);
  244. emit totalScoreChanged();
  245. wonStreak = 0;
  246. emit wonStreakChanged();
  247. }
  248. won = false;
  249. emit hasWonChanged();
  250. scoreMultiplier = 1;
  251. score = totalScore();
  252. emit currentScoreChanged();
  253. remaining = 35-wonStreak*3;
  254. if (remaining < 20) {
  255. remaining = 20;
  256. }
  257. emit timeRemainingChanged();
  258. //Assign game properties
  259. QList<int> usedProperties;
  260. while (usedProperties.count()<10) {
  261. int propertyId = rand() % suspectProperties.count();
  262. while (usedProperties.contains(propertyId)) {
  263. propertyId = rand() % suspectProperties.count();
  264. }
  265. usedProperties << propertyId;
  266. }
  267. int incriminatingInfo = (rand() % 2) + 3;
  268. fEvidences = 0;
  269. emit foundEvidencesChanged();
  270. nEvidences = -1;
  271. int evidenceTypeId = 0;
  272. foreach (EvidenceType *e, tileTypes) {
  273. e->setId(evidenceTypeId);
  274. int evidences = e->number();
  275. while ( evidences ) {
  276. int col = int((double(rand()) / double(RAND_MAX)) * numCols);
  277. int row = int((double(rand()) / double(RAND_MAX)) * numRows);
  278. TileData* t = tile(row,col);
  279. if (t && !t->hasEvidence()) {
  280. t->setHasEvidence( true );
  281. t->setType(e);
  282. if (evidenceTypeId==1) {
  283. startScene = rand() % startScenes.count();
  284. t->flip();
  285. }
  286. if (evidenceTypeId==3) {
  287. t->setPropertyId(usedProperties[evidences+1]);
  288. }
  289. if (evidenceTypeId==4) {
  290. if (evidences == 2) {
  291. t->setPropertyId(usedProperties[0]);
  292. } else {
  293. t->setPropertyId(usedProperties[1]);
  294. }
  295. }
  296. if (evidenceTypeId==6) {
  297. alibiId = rand() % numSuspects;
  298. while (alibiId==killerId) {
  299. alibiId = rand() % numSuspects;
  300. }
  301. }
  302. if (evidenceTypeId==8) {
  303. int evidenceProperty = -1;
  304. int evidenceSuspect = -1;
  305. if (evidences == 10) {
  306. evidenceProperty = 0;
  307. evidenceSuspect = killerId;
  308. } else if (evidences == 9) {
  309. evidenceProperty = 1;
  310. evidenceSuspect = killerId;
  311. } else if (evidences > (10 - incriminatingInfo)) {
  312. int suspectId = rand() % numSuspects;
  313. while (suspectId==killerId) {
  314. suspectId = rand() % numSuspects;
  315. }
  316. int evidenceId = rand() % 2;
  317. if (_suspects[suspectId]->evidences().contains(evidenceId)) {
  318. evidenceId = evidenceId == 1 ? 0 : 1;
  319. }
  320. evidenceProperty = evidenceId;
  321. evidenceSuspect = suspectId;
  322. } else {
  323. int suspectCounter = 0;
  324. foreach(SuspectData* s, _suspects) {
  325. if (s->evidences().count() < 2) {
  326. int evidenceId = (rand()%8)+2;
  327. while (s->evidences().contains(evidenceId)) {
  328. evidenceId = (rand()%8)+2;
  329. }
  330. evidenceProperty = evidenceId;
  331. evidenceSuspect = suspectCounter;
  332. break;
  333. }
  334. suspectCounter++;
  335. }
  336. }
  337. _suspects[evidenceSuspect]->assignEvidence(evidenceProperty);
  338. t->setSuspectId(evidenceSuspect);
  339. t->setPropertyId(usedProperties[evidenceProperty]);
  340. }
  341. evidences--;
  342. nEvidences++;
  343. }
  344. }
  345. evidenceTypeId++;
  346. }
  347. emit numEvidencesChanged();
  348. //Set hints
  349. for (int r = 0; r < numRows; r++) {
  350. for (int c = 0; c < numCols; c++) {
  351. TileData* t = tile(r, c);
  352. if (t) {
  353. int hint = getHint(r,c);
  354. t->setHint(hint);
  355. }
  356. }
  357. }
  358. //Flip 3 random evidence
  359. int startFlipNumber = 3;
  360. while (startFlipNumber) {
  361. int col = int((double(rand()) / double(RAND_MAX)) * numCols);
  362. int row = int((double(rand()) / double(RAND_MAX)) * numRows);
  363. TileData* t = tile( row, col );
  364. while (t->hasEvidence() || t->flipped() || t->hint()==0 ) {
  365. col = int((double(rand()) / double(RAND_MAX)) * numCols);
  366. row = int((double(rand()) / double(RAND_MAX)) * numRows);
  367. t = tile( row, col );
  368. }
  369. t->flip();
  370. startFlipNumber--;
  371. }
  372. refreshLanguage(true);
  373. setPlaying(true);
  374. if (_settings->value("first")!="1") {
  375. _settings->setValue("first", "1");
  376. emit openWelcomeDialog();
  377. }
  378. }
  379. void EvidencehuntGame::reset() {
  380. foreach(TileData* t, _tiles){
  381. t->unflip();
  382. t->setHasFlag(false);
  383. }
  384. foreach(SuspectData* s, _suspects) {
  385. s->unflip();
  386. s->include();
  387. }
  388. isSolveMode = false;
  389. emit solveModeChanged();
  390. nFlags = 0;
  391. emit numFlagsChanged();
  392. fEvidences = 0;
  393. emit foundEvidencesChanged();
  394. setPlaying(false);
  395. QTimer::singleShot(600, this, SLOT(setBoard()));
  396. }
  397. int EvidencehuntGame::getHint(int row, int col)
  398. {
  399. TileData* t = tile(row, col);
  400. int modifier = 0;
  401. if (t->hasEvidence()) {
  402. modifier = -1;
  403. }
  404. int hint = 0;
  405. for (int c = col-1; c <= col+1; c++)
  406. for (int r = row-1; r <= row+1; r++) {
  407. TileData* t = tile(r, c);
  408. if (t && t->hasEvidence()) {
  409. hint++;
  410. }
  411. }
  412. return hint + modifier;
  413. }
  414. EvidenceType* EvidencehuntGame::getType(int row, int col) {
  415. TileData* t = tile(row, col);
  416. return t->type();
  417. }
  418. bool EvidencehuntGame::suspectFlip(int id) {
  419. SuspectData *s = suspect(id);
  420. if (!s->flipped()) {
  421. s->flip();
  422. } else {
  423. s->unflip();
  424. }
  425. return true;
  426. }
  427. bool EvidencehuntGame::suspectExclude(int id) {
  428. SuspectData *s = suspect(id);
  429. if (!s->excluded()) {
  430. s->exclude();
  431. } else {
  432. s->include();
  433. }
  434. return true;
  435. }
  436. bool EvidencehuntGame::guessMurderer(int id) {
  437. if(!playing)
  438. return false;
  439. if(id == killerId){
  440. won = true;
  441. hasWonChanged();
  442. setPlaying(false);
  443. score += remaining*defaultScore*scoreMultiplier;
  444. emit currentScoreChanged();
  445. QString message = "\n\n"+tr("__KEEPTHISWAY__") + "!";
  446. _evidenceInfo->loadCustomMessage(tr("__CONGRATS__"),tileTypes[4],tr("__FOUNDTHEMURDERER__") + message,"arrest.jpg");
  447. _settings->setValue("currentScore", score);
  448. emit totalScoreChanged();
  449. wonStreak++;
  450. emit wonStreakChanged();
  451. } else {
  452. won = false;
  453. hasWonChanged();
  454. setPlaying(false);
  455. QString message;
  456. if (score > maxScore()) {
  457. message = "\n\n" + tr("__NEWPERSONALBEST__") + "!";
  458. }
  459. _evidenceInfo->loadCustomMessage(tr("__TERRIBLEMISTAKE"), tileTypes[1], tr("__MISSEDTHEMURDERER__") + message, "fail.jpg");
  460. if (score > maxScore()) {
  461. _settings->setValue("maxScore", score);
  462. emit maxScoreChanged();
  463. }
  464. _settings->setValue("lastScore", score);
  465. emit lastScoreChanged();
  466. wonStreak=0;
  467. emit wonStreakChanged();
  468. }
  469. return true;
  470. }
  471. bool EvidencehuntGame::loadEvidence(int row, int col) {
  472. TileData *t = tile(row, col);
  473. _evidenceInfo->loadEvidence(t);
  474. return true;
  475. }
  476. bool EvidencehuntGame::toggleSolve() {
  477. isSolveMode = !isSolveMode;
  478. if (isSolveMode) {
  479. //setPlaying(false);
  480. foreach(SuspectData* s, _suspects) {
  481. s->unflip();
  482. }
  483. }/* else {
  484. setPlaying(true);
  485. }*/
  486. emit solveModeChanged();
  487. return true;
  488. }
  489. void EvidencehuntGame::selectLanguage(int lang) {
  490. if (lang==0) {
  491. _settings->setValue("lang", QString("en_US"));
  492. } else if (lang==1) {
  493. _settings->setValue("lang", QString("hu_HU"));
  494. } else if (lang==2) {
  495. _settings->setValue("lang", QString("sr_RS"));
  496. } else if (lang==3) {
  497. _settings->setValue("lang", QString("it_IT"));
  498. }
  499. loadLanguage();
  500. }
  501. bool EvidencehuntGame::flip(int row, int col)
  502. {
  503. if(!playing)
  504. return false;
  505. TileData *t = tile(row, col);
  506. if (!t || t->hasFlag()) {
  507. return false;
  508. }
  509. if(t->flipped()){
  510. return true;
  511. }
  512. if(remaining<1) {
  513. _evidenceInfo->loadCustomMessage(tr("__TIMEISUP__"),tileTypes[8],tr("__TIMETOSOLVE__"),"time.jpg");
  514. return false;
  515. } else {
  516. remaining--;
  517. emit timeRemainingChanged();
  518. }
  519. t->flip();
  520. if(t->hasEvidence()) {
  521. if(t->type()->id()==2) {
  522. score += 50;
  523. }
  524. if(t->type()->id()==5) {
  525. scoreMultiplier = 2;
  526. }
  527. if(t->type()->id()==7) {
  528. remaining += 5;
  529. emit timeRemainingChanged();
  530. }
  531. if(t->type()->id()==9) {
  532. score += 100;
  533. }
  534. fEvidences++;
  535. emit foundEvidencesChanged();
  536. score += defaultScore * scoreMultiplier;
  537. } else {
  538. score += 1;
  539. }
  540. emit currentScoreChanged();
  541. return true;
  542. }
  543. bool EvidencehuntGame::flag(int row, int col) {
  544. TileData *t = tile(row, col);
  545. if(!t || !playing || t->flipped())
  546. return false;
  547. t->setHasFlag(!t->hasFlag());
  548. nFlags += (t->hasFlag()?1:-1);
  549. emit numFlagsChanged();
  550. return true;
  551. }
  552. void EvidencehuntGame::shareGame() const {
  553. #if defined(Q_EVHUNT_MEEGO)
  554. MDataUri duri;
  555. duri.setMimeType ("text/x-url");
  556. duri.setTextData ("http://www.facebook.com/EvidenceHuntGame");
  557. duri.setAttribute ("title", "EvidenceHunt Game");
  558. duri.setAttribute ("description", tr("__PLAYING__"));
  559. if (duri.isValid()) {
  560. QStringList items;
  561. items << duri.toString();
  562. ShareUiInterface shareIf("com.nokia.ShareUi");
  563. if (shareIf.isValid()) {
  564. shareIf.share (items);
  565. }
  566. }
  567. #endif
  568. }
  569. QString EvidencehuntGame::player() {
  570. QString playerName = _settings->value("player").toString();
  571. if (playerName=="") {
  572. playerName = tr("__PLAYER__") + QString::number(rand() % 99999 + 100000);
  573. }
  574. return playerName;
  575. }
  576. int EvidencehuntGame::lastScore() const {
  577. return _settings->value("lastScore", 0).toInt();
  578. }
  579. int EvidencehuntGame::totalScore() const {
  580. return _settings->value("currentScore", 0).toInt();
  581. }
  582. int EvidencehuntGame::maxScore() const {
  583. return _settings->value("maxScore", 0).toInt();
  584. }
  585. int EvidencehuntGame::maxScoreSubmitted() const {
  586. return _settings->value("maxScoreSubmitted", 0).toInt();
  587. }
  588. void EvidencehuntGame::openScoreboard() {
  589. _scoreboard->getList();
  590. }
  591. void EvidencehuntGame::loadScoreboardPlayers(QList< QHash<QString,QString> > boardData) {
  592. _players.clear();
  593. QList< QHash<QString,QString> >::iterator i;
  594. for (i = boardData.begin(); i != boardData.end(); ++i) {
  595. QHash<QString,QString> currentPlayerData = *i;
  596. _players << new TopPlayerData(currentPlayerData.value("name"),currentPlayerData.value("score"),currentPlayerData.value("position"));
  597. }
  598. emit scoreboardLoaded();
  599. }
  600. bool EvidencehuntGame::submitScore(QString name, int score) {
  601. _settings->setValue("player", name);
  602. emit playerChanged();
  603. _scoreboard->submitScore(name, score);
  604. return true;
  605. }
  606. void EvidencehuntGame::boardSubmitSuccess(int submittedScore) {
  607. _settings->setValue("maxScoreSubmitted", submittedScore);
  608. emit maxScoreSubmittedChanged();
  609. }