GameLogic.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. #include <dolphin/helpers/dolphin_deed.h>
  2. #include <dolphin/dolphin.h>
  3. #include <notification/notification_messages.h>
  4. #include "GameLogic.h"
  5. #include "utils/Sprite.h"
  6. #include "assets.h"
  7. //#define SOLVE_TEST
  8. static Sprite logo = Sprite(sprite_logo, BlackOnly);
  9. static Sprite solve = Sprite(sprite_solve, BlackOnly);
  10. static Sprite main_image = Sprite(sprite_main_image, BlackOnly);
  11. static Sprite start = Sprite(sprite_start, BlackOnly);
  12. GameLogic::GameLogic(RenderBuffer *b, InputEventHandler *inputHandler, NotificationApp *notification_app) : buffer(b),
  13. notification(
  14. notification_app) {
  15. inputHandler->subscribe(this, [](void *ctx, int key, InputType type) {
  16. auto *inst = (GameLogic *) ctx;
  17. inst->Input(key, type);
  18. });
  19. }
  20. void GameLogic::Input(int key, InputType type) {
  21. if (type == InputTypeShort) {
  22. if (key == InputKeyBack && state == Play) {
  23. state = Logo;
  24. target[0] = 0;
  25. target[1] = 0;
  26. return;
  27. } else if (key == InputKeyOk) {
  28. if (state == Logo) {
  29. state = Intro;
  30. dolphin_deed(DolphinDeedPluginGameStart);
  31. return;
  32. }
  33. if (state == Solve) {
  34. end = furi_get_tick();
  35. QuickSolve();
  36. return;
  37. }
  38. if (state == Finish) {
  39. dolphin_deed(DolphinDeedPluginGameWin);
  40. state = Logo;
  41. return;
  42. } else if (state == Intro) {
  43. for (int i = 0; i < 7; i++) {
  44. while ((int) tableau[i].size() < (i + 1)) {
  45. tableau[i].push_back(stock.pop_back());
  46. }
  47. tableau[i].peek_back()->exposed = true;
  48. }
  49. tempCard = nullptr;
  50. state = Play;
  51. startTime = furi_get_tick();
  52. buffer->clear();
  53. DrawPlayScene();
  54. } else if (state == Play) {
  55. if (selection[0] == 0 && selection[1] == 0) {
  56. //Cycle waste and stock
  57. if (hand.size() == 0) {
  58. if (stock.size() > 0) {
  59. //move from stock to waste
  60. waste.push_back(stock.pop_back());
  61. waste.peek_back()->exposed = true;
  62. } else {
  63. //move back all the card
  64. while (waste.size() > 0) {
  65. waste.peek_back()->exposed = false;
  66. stock.push_back(waste.pop_back());
  67. }
  68. }
  69. return;
  70. }
  71. return;
  72. } else if (selection[1] == 1 || selection[0] > 0) {
  73. PickAndPlace();
  74. }
  75. return;
  76. }
  77. return;
  78. }
  79. if (state == Play)
  80. HandleNavigation(key);
  81. } else if (type == InputTypeLong) {
  82. switch (key) {
  83. case InputKeyLeft:
  84. selection[0] = 0;
  85. selectedCard = 1;
  86. break;
  87. case InputKeyRight:
  88. selection[0] = 6;
  89. selectedCard = 1;
  90. break;
  91. case InputKeyUp:
  92. selectedCard = 1;
  93. selection[1] = 0;
  94. break;
  95. case InputKeyOk:
  96. if (CanSolve()) {
  97. state = Solve;
  98. break;
  99. }
  100. //quick place
  101. if (state == Play && (selection[0] == 1 || selection[1] == 1) && selectedCard == 1) {
  102. Card *c = selection[1] == 0 ? waste.peek_back() : tableau[selection[0]].peek_back();
  103. if (!c->exposed) return;
  104. for (int i = 0; i < 4; i++) {
  105. if (c->CanPlaceFoundation(foundation[i].peek_back())) {
  106. if (selection[1] == 0)
  107. foundation[i].push_back(waste.pop_back());
  108. else
  109. foundation[i].push_back(tableau[selection[0]].pop_back());
  110. return;
  111. }
  112. }
  113. PlayError();
  114. }
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. if (selection[1] == 0 && selection[0] == 2) { //skip empty space
  121. selection[0] += key == InputKeyRight ? 1 : -1;
  122. }
  123. }
  124. void GameLogic::PickAndPlace() {
  125. //pick and place waste
  126. if (selection[0] == 1 && selection[1] == 0) {
  127. if (waste.size() > 0 && hand.size() == 0) {
  128. hand.push_back(waste.pop_back());
  129. target[0] = 1;
  130. target[1] = 0;
  131. } else if (hand.size() == 1 && target[0] == 1 && target[1] == 0) {
  132. waste.push_back(hand.pop_back());
  133. target[0] = 0;
  134. target[1] = 0;
  135. } else {
  136. PlayError();
  137. }
  138. }
  139. //place to foundation
  140. else if (selection[1] == 0 && selection[0] > 2) {
  141. if (hand.size() == 1) {
  142. uint8_t id = selection[0] - 3;
  143. if (hand.peek_back()->CanPlaceFoundation(foundation[id].peek_back())) {
  144. foundation[id].push_back(hand.pop_back());
  145. target[0] = selection[0];
  146. target[1] = selection[1];
  147. } else {
  148. PlayError();
  149. }
  150. } else {
  151. PlayError();
  152. }
  153. }
  154. //pick and place columns
  155. else if (selection[1] == 1) {
  156. auto &tbl = tableau[selection[0]];
  157. if (hand.size() == 0) {
  158. if(tbl.peek_back()) {
  159. if (!tbl.peek_back()->exposed) {
  160. tbl.peek_back()->exposed = true;
  161. } else {
  162. uint8_t count = selectedCard;
  163. while (count > 0) {
  164. hand.push_front(tbl.pop_back());
  165. count--;
  166. }
  167. selectedCard = 1;
  168. target[0] = selection[0];
  169. target[1] = selection[1];
  170. }
  171. } else {
  172. PlayError();
  173. }
  174. } else if ((target[0] == selection[0] && target[1] == selection[1]) ||
  175. hand.peek_front()->CanPlaceColumn(tbl.peek_back())) {
  176. while (hand.size() > 0) {
  177. tbl.push_back(hand.pop_front());
  178. }
  179. target[0] = 0;
  180. target[1] = 0;
  181. } else {
  182. PlayError();
  183. }
  184. }
  185. for (uint8_t i = 0; i < 4; i++) {
  186. if (foundation[i].size() == 0 || foundation[i].peek_back()->value != KING)
  187. return;
  188. }
  189. buffer->clear();
  190. DrawPlayScene();
  191. selectedCard = 0;
  192. state = Finish;
  193. }
  194. void GameLogic::HandleNavigation(int key) {
  195. if (key == InputKeyLeft && selection[0] > 0) {
  196. selectedCard = 1;
  197. selection[0]--;
  198. } else if (key == InputKeyRight && selection[0] < 6) {
  199. selectedCard = 1;
  200. selection[0]++;
  201. } else if (key == InputKeyUp && selection[1] == 1) {
  202. auto &tbl = tableau[selection[0]];
  203. uint8_t first = FirstNonFlipped(tbl);
  204. if (tbl.size() > 0 && first < tbl.size() - selectedCard && hand.size() == 0) {
  205. selectedCard++;
  206. } else {
  207. selectedCard = 1;
  208. selection[1]--;
  209. }
  210. } else if (key == InputKeyDown && selection[1] == 0) {
  211. selectedCard = 1;
  212. selection[1]++;
  213. } else if (selection[1] == 1 && selectedCard > 1) {
  214. selectedCard--;
  215. }
  216. }
  217. void GameLogic::Update(float delta) {
  218. //keep the buffer for the falling animation to achieve the trailing effect
  219. if (state != Finish) {
  220. buffer->clear();
  221. }
  222. switch (state) {
  223. case Logo:
  224. Reset();
  225. buffer->draw(&logo, (Vector) {60, 30}, 0);
  226. buffer->draw(&main_image, (Vector) {115, 25}, 0);
  227. buffer->draw(&start, (Vector) {64, 55}, 0);
  228. break;
  229. case Intro:
  230. DoIntro(delta);
  231. dirty = true;
  232. end = 0;
  233. break;
  234. case Play:
  235. DrawPlayScene();
  236. if (CanSolve()) {
  237. buffer->draw_rbox(25, 53, 101, 64, Black);
  238. buffer->draw_rbox(26, 54, 100, 63, White);
  239. buffer->draw(&solve, (Vector) {64, 58}, 0);
  240. end = furi_get_tick();
  241. }
  242. break;
  243. case Solve:
  244. DrawPlayScene();
  245. HandleSolve(delta);
  246. dirty = true;
  247. break;
  248. case Finish:
  249. dirty = true;
  250. FallingCard(delta);
  251. break;
  252. default:
  253. break;
  254. }
  255. buffer->swap();
  256. readyToRender = true;
  257. }
  258. void GameLogic::Reset() {
  259. dolphin_deed(DolphinDeedPluginGameStart);
  260. delete tempCard;
  261. stock.deleteData();
  262. stock.clear();
  263. waste.deleteData();
  264. waste.clear();
  265. tempPos = {0, 0};
  266. selection[0] = 0;
  267. selection[1] = 0;
  268. target[0] = 0;
  269. selectedCard = 1;
  270. target[1] = -1;
  271. for (int i = 0; i < 7; i++) {
  272. tableau[i].deleteData();
  273. tableau[i].clear();
  274. if (i < 4) {
  275. foundation[i].deleteData();
  276. foundation[i].clear();
  277. }
  278. }
  279. GenerateDeck();
  280. }
  281. bool GameLogic::CanSolve() {
  282. for (uint8_t i = 0; i < 7; i++) {
  283. if (tableau[i].peek_front() && !tableau[i].peek_front()->exposed)
  284. return false;
  285. }
  286. return state == Play;
  287. }
  288. void GameLogic::GenerateDeck() {
  289. int cards_count = 52;
  290. uint8_t cards[cards_count];
  291. for (int i = 0; i < cards_count; i++) cards[i] = i % 52;
  292. srand(DWT->CYCCNT);
  293. #ifndef SOLVE_TEST
  294. //reorder
  295. for (int i = 0; i < cards_count; i++) {
  296. int r = i + (rand() % (cards_count - i));
  297. uint8_t card = cards[i];
  298. cards[i] = cards[r];
  299. cards[r] = card;
  300. }
  301. #endif
  302. //Init deck list
  303. for (int i = 0; i < cards_count; i++) {
  304. int letter = cards[i] % 13;
  305. int suit = cards[i] / 13;
  306. stock.push_back(new Card(suit, letter));
  307. }
  308. }
  309. GameLogic::~GameLogic() {
  310. stock.deleteData();
  311. stock.clear();
  312. waste.deleteData();
  313. waste.clear();
  314. hand.deleteData();
  315. hand.clear();
  316. delete tempCard;
  317. for (int i = 0; i < 7; i++) {
  318. tableau[i].deleteData();
  319. tableau[i].clear();
  320. if (i < 4) {
  321. foundation[i].deleteData();
  322. foundation[i].clear();
  323. }
  324. }
  325. }
  326. Vector pos, targetPos;
  327. void GameLogic::DoIntro(float delta) {
  328. //render next after finish
  329. #ifdef SOLVE_TEST
  330. startTime = furi_get_tick();
  331. state = Play;
  332. buffer->clear();
  333. DrawPlayScene();
  334. return;
  335. #endif
  336. if (!buffer) return;
  337. buffer->clear();
  338. DrawPlayScene();
  339. if (tempCard) {
  340. targetPos = {
  341. 2.0f + (float) target[0] * 18,
  342. MIN(25.0f + (float) target[1] * 4, 36)
  343. };
  344. tempTime += delta * 10;
  345. pos = Vector::Lerp(tempPos, targetPos, MIN(tempTime, 1));
  346. tempCard->Render((int) pos.x, (int) pos.y, false, buffer);
  347. float distance = targetPos.distance(pos);
  348. if (distance < 0.01) {
  349. tempCard = nullptr;
  350. tableau[target[0]].push_back(stock.pop_back());
  351. tableau[target[0]].peek_back()->exposed = target[0] == target[1];
  352. if (target[0] == 6 && target[1] == 6) {
  353. startTime = furi_get_tick();
  354. state = Play;
  355. buffer->clear();
  356. DrawPlayScene();
  357. }
  358. }
  359. } else {
  360. tempTime = 0;
  361. tempCard = stock.peek_back();
  362. tempPos.x = 2;
  363. tempPos.y = 1;
  364. if (target[0] == target[1]) {
  365. target[0]++;
  366. target[1] = 0;
  367. } else {
  368. target[1]++;
  369. }
  370. }
  371. }
  372. void GameLogic::DrawPlayScene() {
  373. if (stock.size() > 0) {
  374. if (stock.size() > 1) {
  375. stock.peek_back()->Render(2, 1, true, buffer);
  376. stock.peek_back()->Render(0, 0, selection[0] == 0 && selection[1] == 0, buffer);
  377. } else {
  378. stock.peek_back()->Render(2, 1, selection[0] == 0 && selection[1] == 0, buffer);
  379. }
  380. } else
  381. Card::TryRender(nullptr, 2, 1, selection[0] == 0 && selection[1] == 0, buffer);
  382. Card::TryRender(waste.peek_back(), 20, 1, selection[0] == 1 && selection[1] == 0, buffer);
  383. int i;
  384. for (i = 0; i < 4; i++) {
  385. Card::TryRender(foundation[i].peek_back(), 56 + i * 18, 1, selection[0] == i + 3 && selection[1] == 0, buffer);
  386. }
  387. for (i = 0; i < 7; i++) {
  388. DrawColumn(2 + i * 18, 25, (selection[0] == i && selection[1] == 1) ? selectedCard : 0, i);
  389. }
  390. if (hand.size() > 0) {
  391. if (selection[1] == 0)
  392. DrawColumn(10 + selection[0] * 18, 15 + selection[1] * 25, hand.size(), -1);
  393. else {
  394. int shift = MIN((int) tableau[selection[0]].size(), 4) * 4;
  395. DrawColumn(10 + selection[0] * 18, 30 + shift, hand.size(), -1);
  396. }
  397. }
  398. }
  399. void GameLogic::DrawColumn(uint8_t x, uint8_t y, uint8_t selected, int8_t column) {
  400. UNUSED(selected);
  401. auto &deck = column >= 0 ? tableau[column] : hand;
  402. if (deck.size() == 0 && column >= 0) {
  403. Card::RenderEmptyCard(x, y, buffer);
  404. if (selected == 1)
  405. buffer->draw_rbox(x + 1, y + 1, x + 16, y + 22, Flip);
  406. return;
  407. }
  408. uint8_t selection = deck.size() - selected;
  409. // if (selected != 0) selection--;
  410. uint8_t loop_end = deck.size();
  411. uint8_t loop_start = MAX(loop_end - 4, 0);
  412. uint8_t position = 0;
  413. uint8_t first_non_flipped = FirstNonFlipped(deck);
  414. bool had_top = false;
  415. bool showDark = column >= 0;
  416. // Draw the first flipped and non-flipped card with adjusted visibility
  417. if (first_non_flipped <= loop_start && selection != first_non_flipped) {
  418. // Draw a card back if it is not the first card
  419. if (first_non_flipped > 0) {
  420. Card::RenderBack(x, y + position, false, buffer, 5);
  421. // Increment loop start index and position
  422. position += 4;
  423. loop_start++;
  424. had_top = true;
  425. }
  426. // Draw the front side of the first non-flipped card
  427. deck[first_non_flipped]->Render(x, y + position, false, buffer, deck.size() == 1 ? 22 : 9);
  428. position += 8;
  429. loop_start++; // Increment loop start index
  430. }
  431. // Draw the selected card with adjusted visibility
  432. if (loop_start > selection) {
  433. if (!had_top && first_non_flipped > 0) {
  434. Card::RenderBack(x, y + position, false, buffer, 5);
  435. position += 4;
  436. loop_start++;
  437. }
  438. // Draw the front side of the selected card
  439. deck[selection]->Render(x, y + position, showDark, buffer, 9);
  440. position += 8;
  441. loop_start++; // Increment loop start index
  442. }
  443. int height = 5;
  444. uint8_t i = 0;
  445. for (auto *card: deck) {
  446. if (i >= loop_start && i < loop_end) {
  447. height = 5;
  448. if ((i + 1) == loop_end) height = 22;
  449. else if (i == selection || i == first_non_flipped) height = 9;
  450. card->Render(x, y + position, i == selection && showDark, buffer, height);
  451. if (i == selection || i == first_non_flipped)position += 4;
  452. position += 4;
  453. }
  454. i++;
  455. }
  456. }
  457. int8_t GameLogic::FirstNonFlipped(const List<Card> &deck) {
  458. int8_t index = 0;
  459. for (auto *card: deck) {
  460. if (card->exposed) return index;
  461. index++;
  462. }
  463. return -1;
  464. }
  465. void GameLogic::HandleSolve(float delta) {
  466. if (tempCard) {
  467. tempTime += delta * 8;
  468. Vector finalPos{56 + (float) target[0] * 18, 2};
  469. if (tempTime > 1) tempTime = 1;
  470. Vector localpos = Vector::Lerp(tempPos, finalPos, tempTime);
  471. tempCard->Render((uint8_t) localpos.x, (uint8_t) localpos.y, false, buffer);
  472. if (finalPos.distance(localpos) < 0.01) {
  473. foundation[target[0]].push_back(tempCard);
  474. tempCard = nullptr;
  475. }
  476. //check finish
  477. uint8_t size = 0;
  478. for (uint8_t i = 0; i < 4; i++) {
  479. if (foundation[i].size() > 0 && foundation[i].peek_back()->value == KING)
  480. size++;
  481. }
  482. if (size == 4) {
  483. buffer->clear();
  484. selectedCard = 0;
  485. DrawPlayScene();
  486. state = Finish;
  487. return;
  488. }
  489. } else {
  490. tempTime = 0;
  491. //search the lowest card
  492. int lowestSuit = -2, lowestValue = 13;
  493. for (int i = 0; i < 4; i++) {
  494. auto &fnd = foundation[i];
  495. if (foundation[i].size() == 0) {
  496. //find the missing suit
  497. int foundations[4] = {0, 0, 0, 0};
  498. for (int j = 0; j < 4; j++) {
  499. if (foundation[j].size() > 0) {
  500. foundations[foundation[j].peek_front()->suit] = 1;
  501. }
  502. }
  503. for (int j = 0; j < 4; j++) {
  504. if (foundations[j] == 0) {
  505. lowestSuit = j;
  506. lowestValue = -1;
  507. target[0] = (float) j;
  508. break;
  509. }
  510. }
  511. break;
  512. }
  513. if (i == 0 || (lowestValue + 1) % 13 > (fnd.peek_back()->value + 1) % 13) {
  514. lowestSuit = fnd.peek_back()->suit;
  515. lowestValue = fnd.peek_back()->value;
  516. target[0] = (float) i;
  517. }
  518. }
  519. Card lowest(lowestSuit, lowestValue);
  520. //try to find it in tableau
  521. for (int i = 0; i < 7; i++) {
  522. auto &tbl = tableau[i];
  523. if (tbl.peek_back() && tbl.peek_back()->CanPlaceFoundation(&lowest)) {
  524. tempCard = tbl.pop_back();
  525. int y = MIN((int) tableau[i].size(), 4) * 4 + 25;
  526. tempPos.x = 2 + (float) i * 18;
  527. tempPos.y = (float) y;
  528. return;
  529. }
  530. }
  531. //try to find in waste
  532. int index = -1;
  533. for (auto *w: waste) {
  534. index++;
  535. if (w->CanPlaceFoundation(&lowest)) {
  536. tempCard = waste.extract(index);
  537. tempCard->exposed = true;
  538. tempPos.x = 20;
  539. tempPos.y = 1;
  540. return;
  541. }
  542. }
  543. index = -1;
  544. //try to find in stock
  545. for (auto *w: stock) {
  546. index++;
  547. if (w->CanPlaceFoundation(&lowest)) {
  548. tempCard = stock.extract(index);
  549. tempCard->exposed = true;
  550. tempPos.x = 2;
  551. tempPos.y = 1;
  552. return;
  553. }
  554. }
  555. }
  556. }
  557. void GameLogic::QuickSolve() {
  558. if (tempCard) {
  559. delete tempCard;
  560. tempCard = nullptr;
  561. }
  562. waste.deleteData();
  563. waste.clear();
  564. stock.deleteData();
  565. stock.clear();
  566. for (uint8_t i = 0; i < 7; i++) {
  567. tableau[i].deleteData();
  568. tableau[i].clear();
  569. }
  570. int foundations[4] = {0, 0, 0, 0};
  571. for (int j = 0; j < 4; j++) {
  572. if (foundation[j].size() > 0) {
  573. foundations[foundation[j].peek_front()->suit] = 1;
  574. }
  575. }
  576. for (int j = 0; j < 4; j++) {
  577. if (foundations[j] == 0) {
  578. //seed the foundation
  579. foundation[j].push_back(new Card(j, ACE));
  580. foundation[j].peek_back()->exposed = true;
  581. }
  582. }
  583. for (uint8_t i = 0; i < 4; i++) {
  584. auto &fnd = foundation[i];
  585. if (fnd.peek_back()->value == ACE) {
  586. fnd.push_back(new Card(fnd.peek_back()->suit, TWO));
  587. fnd.peek_back()->exposed = true;
  588. }
  589. while (fnd.peek_back()->value != KING) {
  590. fnd.push_back(new Card(fnd.peek_back()->suit, fnd.peek_back()->value + 1));
  591. fnd.peek_back()->exposed = true;
  592. }
  593. }
  594. buffer->clear();
  595. DrawPlayScene();
  596. selectedCard = 0;
  597. state = Finish;
  598. }
  599. void GameLogic::FallingCard(float delta) {
  600. UNUSED(delta);
  601. if (tempCard) {
  602. if ((furi_get_tick() - tempTime) > 12) {
  603. tempTime = furi_get_tick();
  604. tempPos.x += velocity.x;
  605. tempPos.y -= velocity.y;
  606. if (tempPos.y > 41) {
  607. velocity.y *= -0.8;
  608. tempPos.y = 41;
  609. PlayBounce();
  610. } else {
  611. velocity.y -= 1;
  612. if (velocity.y < -10) velocity.y = -10;
  613. }
  614. tempCard->Render((int8_t) tempPos.x, (int8_t) tempPos.y, false, buffer);
  615. if (tempPos.x < -18 || tempPos.x > 128) {
  616. delete tempCard;
  617. tempCard = nullptr;
  618. }
  619. }
  620. } else {
  621. float r1 = 2.0 * (float) (rand() % 2) - 1.0; // random number in range -1 to 1
  622. if (r1 == 0) r1 = 0.1;
  623. float r2 = inverse_tanh(r1);
  624. velocity.x = (float) (tanh(r2)) * (rand() % 3 + 1);
  625. if (velocity.x == 0) velocity.x = 1;
  626. velocity.y = (rand() % 3 + 1);
  627. if (foundation[selectedCard].size() > 0) {
  628. tempCard = foundation[selectedCard].pop_back();
  629. tempCard->exposed = true;
  630. tempPos.x = 56 + selectedCard * 18;
  631. tempPos.y = 2;
  632. selectedCard = (uint8_t) (selectedCard + 1) % 4;
  633. } else {
  634. state = Logo;
  635. return;
  636. }
  637. }
  638. }
  639. static const NotificationSequence sequence_fail = {
  640. &message_vibro_on,
  641. &message_note_c4,
  642. &message_delay_10,
  643. &message_vibro_off,
  644. &message_sound_off,
  645. &message_delay_10,
  646. &message_vibro_on,
  647. &message_note_a3,
  648. &message_delay_10,
  649. &message_vibro_off,
  650. &message_sound_off,
  651. NULL,
  652. };
  653. static const NotificationSequence sequence_bounce = {
  654. &message_vibro_on,
  655. &message_note_c4,
  656. &message_delay_10,
  657. &message_vibro_off,
  658. &message_sound_off,
  659. NULL,
  660. };
  661. void GameLogic::PlayError() {
  662. notification_message(notification, (const NotificationSequence *) &sequence_fail);
  663. }
  664. void GameLogic::PlayBounce() {
  665. notification_message(notification, (const NotificationSequence *) &sequence_bounce);
  666. }