Advertisement
Guest User

NIM 20.11.2019

a guest
Nov 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.06 KB | None | 0 0
  1. // unicode needs to be enabled so
  2. //that WHITESPACE character can be used
  3. #define _WIN32_WINNT 0x0601
  4.  
  5. #ifndef UNICODE
  6. #define UNICODE
  7. #define UNICODE_WAS_UNDEFINED
  8. #endif
  9.  
  10. #include <Windows.h>
  11.  
  12. #ifdef UNICODE_WAS_UNDEFINED
  13. #undef UNICODE
  14. #endif
  15.  
  16. #define WHITE_SPACE 9608
  17.  
  18. #include <stdio.h>
  19. #include <vector>
  20.  
  21. //used to resize the console cell
  22. //important for w10 compatibility
  23. typedef struct _CONSOLE_FONT_INFOEX
  24. {
  25. ULONG cbSize;
  26. DWORD nFont;
  27. COORD dwFontSize;
  28. UINT FontFamily;
  29. UINT FontWeight;
  30. WCHAR FaceName[LF_FACESIZE];
  31. }CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
  32.  
  33. //the function declaration begins
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsoleOutput,
  38. BOOL bMaximumWindow,
  39. PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx);
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. //the function declaration ends
  44.  
  45. //resizes cell
  46. //important for w10 compatibility
  47. void setFontSize(int w, int h)
  48. {
  49. CONSOLE_FONT_INFOEX fontStructure={0};
  50. fontStructure.cbSize=sizeof(fontStructure);
  51. fontStructure.dwFontSize.X=w;
  52. fontStructure.dwFontSize.Y=h;
  53. HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
  54. SetCurrentConsoleFontEx(hConsole, true, &fontStructure);
  55. }
  56.  
  57. //{ variables
  58. int screen_width = 80, screen_height = 25;//screen dimensions in columns/rows
  59. bool running = true;//the boolean used for the game loop
  60. int turn = 0;//indicated who's player turn is
  61. int default_turn = 0;//retains the preference of who starts the rounds
  62. wchar_t player1[11] = L"Mitrutz";//can be modified at runtime
  63. wchar_t player2[11] = L"Matei";//can be modified at runtime
  64. wchar_t won[] = L"won";//displayed when the game is won next to the player's name
  65. bool restart_game = false;//when true, the piles get filled and the game begins again
  66. wchar_t new_game_wchar[] = L"new game\0";//`new game` button text
  67. wchar_t unselected_coin_texture[51] = L" ######## ############################## ######## ";
  68. wchar_t selected_coin_texture[51] = L" ######## ############################## ######## ";
  69. //selected_coin_texture is painted to white in main (the white character cant be copy-pasted)
  70. bool updated = false;//indicates if the turn has changed
  71. int nrCoins[] = {0, 1, 2, 3, 4, 5};//keeps count of the coins (on each column)
  72. const int cell_count = screen_height * screen_width;//number of total cells on screen
  73. int cell_size_px_x = 8, cell_size_px_y = 12; //used to calculate over which cell the mouse hovers
  74. float move_window_x = 10.4f, move_window_y = 14.0;
  75. COORD zerozero = {0, 0};
  76. wchar_t options_[] = L"options", game_[] = L"game"
  77. ,how_to_play_[] = L"how to play ", nullstr[] = L" ", turn_wchr[] = L"Turn:";
  78. wchar_t *screen = new wchar_t[screen_width*screen_height];//console graphic buffer
  79. HWND hwnd;//used in console manipulation
  80. int mi, mj;//the line and column over which the mouse hovers
  81. wchar_t over_score[9] = {175, 175, 175, 175, 175, 175, 175, 175, 0};
  82. wchar_t under_score[9] = {L'_', L'_', L'_', L'_', L'_', L'_', L'_', L'_', 0};
  83. wchar_t horizontal_line[12] = {9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 0};
  84. int scene = 1;//indicates the current scene(game/options/how_to_play scene)
  85. wchar_t score_wchr[] = {'S', 'c', 'o', 'r', 'e', ':', 0};
  86. int score1(0), score2(0);//keep track of score
  87. bool score_updated = false;//checks if the score has been updated
  88. wchar_t player_names_wchr[] = L"Player names:";
  89. HANDLE hConsole;DWORD dwBytesWritten = 0;//miscellaneous
  90. bool widgets_updated;//makes sure multiple widgets can't be open in the same frame
  91. //}
  92. bool testbool = false;
  93.  
  94. void updateVersion()
  95. {
  96. DWORD dwVersion = 0;
  97. DWORD dwMinorVersion = 0;
  98.  
  99. dwVersion = GetVersion();
  100.  
  101. // Get the Windows version.
  102. dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
  103. int version = dwMinorVersion;
  104. if(version == 2)
  105. {
  106. //setting correct window size
  107. setFontSize(12, 20);///win10
  108.  
  109. move_window_x = 12.5;///win10 used to be .5
  110. move_window_y = 22; ///win10
  111. cell_size_px_x = 10;
  112. cell_size_px_y = 20;
  113. }
  114.  
  115. MoveWindow(hwnd, 0, 0, screen_width*move_window_x, screen_height*move_window_y, TRUE);
  116. }
  117.  
  118. void optionsScene()
  119. {
  120. scene = 2;
  121. }
  122.  
  123. void gameScene()
  124. {
  125. scene = 1;
  126. }
  127.  
  128. void howToPlayScene()
  129. {
  130. scene = 0;
  131. }
  132.  
  133. size_t wstrlen(wchar_t* n)
  134. {
  135. size_t i = 0;
  136. while(n[i])++i;
  137. return i;
  138. }
  139. int print(int n, int x, int y);
  140.  
  141. class Mouse
  142. {
  143. public:
  144.  
  145. void update()//update the state of the mouse
  146. {
  147. if(GetKeyState(VK_LBUTTON) < 0)
  148. {
  149. if(held)
  150. clicked = false;
  151. else
  152. clicked = held = true;
  153. }
  154. else
  155. clicked = held = false;
  156.  
  157. GetCursorPos(&position);
  158. GetWindowRect(hwnd, &r);
  159.  
  160. position.y = position.y - r.top - 30;//30 is the size of the title bar
  161. position.x = position.x - r.left - 8;//idk what 8 is it's also for correction
  162.  
  163. //find out over which cell the mouse hovers
  164. mi = (this->pos().y)/cell_size_px_y;
  165. mj = (this->pos().x)/cell_size_px_x;
  166. }
  167.  
  168. POINT pos()
  169. {
  170. return this->position;
  171. }
  172.  
  173. bool isHeld()
  174. {
  175. return held;
  176. }
  177.  
  178. bool isClicked()
  179. {
  180. return clicked;
  181. }
  182.  
  183. Mouse()
  184. {
  185. clicked = false;
  186. held = false;
  187. position.x = position.y =0;
  188. }
  189.  
  190. private:
  191.  
  192. bool clicked;
  193.  
  194. bool held;
  195.  
  196. POINT position;
  197.  
  198. RECT r;
  199.  
  200. }mouse;
  201.  
  202. class Keyboard
  203. {
  204. public:
  205.  
  206. Keyboard()
  207. {
  208. key = held = 0;
  209. }
  210.  
  211. void update()
  212. {
  213. for (char i = '0'; i <= 'Z'; ++i)
  214. {
  215. if(GetKeyState(i) < 0)
  216. {
  217. if(held == 0)
  218. {
  219. key = held = (wchar_t)i;
  220. if(key >= 'A' && key <= 'Z' && !(GetKeyState(VK_SHIFT) < 0))key = key + ('a' - 'A');
  221. }
  222. else
  223. {
  224. key = 0;
  225. }
  226. return;
  227. }
  228. }
  229.  
  230. key = key + ('a' - 'A');
  231.  
  232. key = held = 0;
  233. print(3, 0, 3);
  234. }
  235.  
  236. wchar_t keyPressed()
  237. {
  238. return key;
  239. }
  240.  
  241. //private:
  242.  
  243. wchar_t key, held;
  244.  
  245. }keyboard;
  246.  
  247. void setrunningtofalse()//end game loop
  248. {
  249. running = false;
  250. }
  251.  
  252. //when start_game is true the piles are filled up again
  253. void setrestart_gametotrue()
  254. {
  255. if(scene==1)restart_game=true;
  256. }
  257.  
  258. short sum();
  259. void changeTurn()
  260. {
  261. if (sum() == 15)
  262. {
  263. turn = 1 - turn;
  264. default_turn = turn;
  265. }
  266. }
  267.  
  268. //can be clicked and have text
  269. class Button
  270. {
  271. public:
  272. // position , size , displayed text , function called when pressed
  273. Button (int i, int j, int isize, int jsize, wchar_t name[], void (*foo)())
  274. {
  275. textsize = 0;
  276. while(name[textsize])
  277. {
  278. text[textsize]=name[textsize];
  279. ++textsize;
  280. }
  281. text[textsize] = L'\0';
  282. func = foo;
  283. left_margin = i;
  284. j1 = j;
  285. right_margin = i + isize;
  286. j2 = j + jsize;
  287.  
  288. }
  289.  
  290. void update()
  291. {
  292. if(mouse.isClicked() && mi >= left_margin && mi < right_margin && mj >= j1 && mj < j2)
  293. func();
  294. }
  295.  
  296. void draw()
  297. {
  298. int aux = 0;
  299. for(int i = left_margin; i < right_margin; i++)
  300. {
  301. for(int j = j1; j < j2; j++)
  302. {
  303. if(aux>=0 && aux < textsize)
  304. screen[i * screen_width + j] = text[aux++];
  305. }
  306. }
  307. }
  308.  
  309. void draw(wchar_t *screen, int screen_width, int i = 0, int j = 0)
  310. {
  311. int aux = 0;
  312. while (text[aux] != 0)
  313. {
  314. screen[i * screen_width + j + aux] = text[aux];
  315. ++aux;
  316. }
  317. }
  318.  
  319. wchar_t* name()
  320. {
  321. return text;
  322. }
  323.  
  324. private:
  325.  
  326. wchar_t text[200];
  327. unsigned short textsize;
  328. short left_margin, right_margin, j1, j2;
  329. void (*func)();
  330. };
  331.  
  332. void quit()
  333. {
  334. exit(1);
  335. }
  336.  
  337. //used in order to check if an area is hovered/clicked
  338. class Coin
  339. {
  340. public:
  341. int left_margin, j1, right_margin, j2;
  342.  
  343. Coin(int i, int j, int isize, int jsize)
  344. {
  345. left_margin = i;
  346. j1 = j;
  347. right_margin = i + isize;
  348. j2 = j + jsize;
  349. }
  350.  
  351. bool hovered(int mi, int mj)
  352. {
  353. if(mi >= left_margin && mi < right_margin && mj >= j1 && mj <j2)
  354. {
  355. if((mi==left_margin || mi == right_margin-1) && (mj == j1 || mj == j2-1))
  356. return false;
  357. return true;
  358. }
  359. return false;
  360. }
  361.  
  362. bool _clicked(int mi, int mj)
  363. {
  364. if(hovered(mi, mj) && mouse.isClicked())
  365. return true;
  366. return false;
  367. }
  368. };
  369.  
  370. //contains coins. when (almost) all Pile instances
  371. //are empty the game is won
  372. //hard coded size of 10 cells
  373. //useless to declare >5 coins
  374. class Pile
  375. {
  376. public:
  377.  
  378. /* position (left side), number of coins it will have*/
  379. Pile(unsigned short i , unsigned short nrcoins)
  380. {
  381. left_margin = i;
  382. right_margin = left_margin + 10;
  383. nPileWidth = 10;
  384.  
  385. coins.clear();
  386. for(int ii = 1; ii <= nrcoins; ii++)
  387. coins.push_back(Coin(screen_height-(ii*5), i, 5, 10));
  388. }
  389.  
  390. //does the same as the constructor
  391. void reset(unsigned short i , unsigned short nrcoins)
  392. {
  393. left_margin = i;
  394. right_margin = left_margin + 10;
  395. nPileWidth = 10;
  396. coins.clear();
  397.  
  398. for(int ii = 1; ii <= nrcoins; ii++)
  399. coins.push_back(Coin(screen_height-(ii*5), i, 5, 10));
  400. }
  401.  
  402. //check if any cell is hovered
  403. //remove the cells from top if also clicked
  404. int update(int mi, int mj)
  405. {
  406. hovered_cell = 0;
  407. for(size_t i = 0; i< coins.size(); i++){
  408. if(coins[i].hovered(mi, mj))
  409. {
  410. hovered_cell = i+1;
  411. i= coins.size();//i goes to end and ends loop
  412. if(mouse.isClicked())
  413. {
  414. while((int)coins.size()>=hovered_cell)
  415. coins.pop_back();
  416. updated = true;
  417. return coins.size();
  418. }
  419. }
  420. }
  421. return coins.size();
  422. }
  423.  
  424. void draw(wchar_t*& screen)
  425. {
  426.  
  427. int i = -1;
  428. while(++i<nPileWidth*screen_height)gBuffer[i]=L' ';
  429.  
  430. if(hovered_cell)
  431. {
  432. for(int i = 0; i<hovered_cell-1; i++)
  433. {
  434. for(int j = 0; j<50; j++)
  435. {
  436. gBuffer[i*nPileWidth*5 + j] = unselected_coin_texture[j];
  437. }
  438. }
  439. for(unsigned short i = hovered_cell-1; i<coins.size(); i++)
  440. for(int j = 0; j<50; j++)
  441. gBuffer[i*nPileWidth*5 + j] = selected_coin_texture[j];
  442. }
  443. else
  444. {
  445. for(unsigned short i = 0; i<coins.size(); i++)
  446. for(int j = 0; j<50; j++)
  447. {
  448. gBuffer[i*nPileWidth*5 + j] = unselected_coin_texture[j];
  449. }
  450. }
  451.  
  452. int qq = 0;
  453. bool done = false;
  454. int gb = screen_height*nPileWidth-1;
  455.  
  456. while(!done && qq < screen_height)
  457. {
  458. for(int ww = 0; ww < nPileWidth; ww++)
  459. {
  460.  
  461. if(gb)
  462. {
  463. int aux = qq*screen_width+ww+left_margin;
  464. if(aux < cell_count) screen[aux] = gBuffer[gb--];
  465. }
  466.  
  467. else done=true;//*/
  468. }
  469. qq++;
  470. }//*/
  471. }
  472.  
  473. private:
  474.  
  475. int left_margin, right_margin, hovered_cell;
  476. std::vector<Coin>coins;
  477. unsigned short nPileWidth;
  478. wchar_t gBuffer[25*50];
  479. };
  480.  
  481. short sum()
  482. {
  483. short s = 0;
  484. for(int yt = 1; yt <= 5; ++yt)
  485. {
  486. s+=nrCoins[yt];
  487. }
  488. return s;
  489. }
  490.  
  491. short cols()
  492. {
  493. short nrc = 0;
  494. for(int yt = 1; yt <= 5; ++yt)
  495. {
  496. nrc += (nrCoins[yt] > 0);
  497. }
  498. return nrc;
  499. }
  500.  
  501. int print(int n, int linear_pos)
  502. {
  503. if (!n)
  504. {
  505. screen[linear_pos] = L'0';
  506. return linear_pos + 2;
  507. }
  508.  
  509. //digit count
  510. int len = 0, aux = n;
  511. while(aux){aux/=10;++len;}
  512. aux = len;
  513.  
  514. if (n < 0)
  515. {
  516. screen[linear_pos] = L'-';
  517. ++linear_pos;
  518. n*=(-1);
  519. }
  520.  
  521. while (n)
  522. {
  523. screen[linear_pos + len - 1] = n%10 + '0';
  524. n/=10; --len;
  525. }
  526.  
  527. return linear_pos + aux + 1;
  528. }
  529.  
  530. int print(int n, int x, int y)
  531. {
  532. int pos = y * screen_width + x;
  533. return print(n, pos);
  534. }
  535.  
  536. int print(int n[], int _count, int linear_position)
  537. {
  538. int i = 0;
  539. while(_count)
  540. {
  541. linear_position = print(n[i], linear_position);
  542. --_count;++i;
  543. }
  544. return linear_position;
  545. }
  546.  
  547. int print(int n[], int _count, int x, int y)
  548. {
  549. int pos = y * screen_width + x;
  550. print(n, _count, pos);
  551. return pos + 2;
  552. }
  553.  
  554. //returns the linear position of the end of
  555. //the string + 1 (good for printing multiple
  556. //strings consecutively)
  557. int print(wchar_t n[], int linear_pos)
  558. {
  559. int i = 0;
  560. while (n[i] != 0)
  561. {
  562. screen[linear_pos + i] = n[i];
  563. ++i;
  564. }
  565. return linear_pos + i + 1;
  566. }
  567.  
  568. int print(wchar_t n[], int x, int y)
  569. {
  570. int pos = y*screen_width + x;
  571. return print(n, pos);
  572. }
  573.  
  574. int print(wchar_t n, int linear_position)
  575. {
  576. screen[linear_position] = n;
  577. return linear_position + 2;
  578. }
  579.  
  580. int print(wchar_t n, int x, int y)
  581. {
  582. int pos = y * screen_width + x;
  583. return print(n, pos);
  584. }
  585.  
  586. print(char n, int linear_position)
  587. {
  588. screen[linear_position] = (wchar_t)n;
  589. return linear_position + 2;
  590. }
  591.  
  592. int print(char n, int x, int y)
  593. {
  594. int pos = y * screen_width + x;
  595. return print(n, pos);
  596. }
  597.  
  598. int print(int n[], int _count, int linear_position, wchar_t delimitator)
  599. {
  600. int i = 0;
  601. while(_count > 1)
  602. {
  603. linear_position = print(n[i], linear_position);
  604. linear_position = print(delimitator, linear_position-1);
  605. --_count;++i;
  606. }
  607.  
  608. linear_position = print(n[i], linear_position);
  609.  
  610. return linear_position;
  611. }
  612.  
  613. int print(int n[], int _count, int x, int y, wchar_t delimitator)
  614. {
  615. int pos = y * screen_width + x;
  616. return print(n, _count, pos, delimitator);
  617. }
  618.  
  619. int print(int n[], int _count, int linear_position, char delimitator)
  620. {
  621. return print(n, _count, linear_position, (wchar_t)delimitator);
  622. }
  623.  
  624. int print(int n[], int _count, int x, int y, char delimitator)
  625. {
  626. int pos = y * screen_width + x;
  627. return print(n, _count, pos, (wchar_t)delimitator);
  628. }
  629.  
  630. //game stuff
  631. Button new_game(16, 1, 1, 8, new_game_wchar, setrestart_gametotrue);
  632. Button ebutton(-2, screen_width-6, 3, 10, nullstr, setrunningtofalse);
  633. Button options_scene(21, 1, 1, 8, options_, optionsScene);
  634. Button game_scene(19, 3, 1, 4, game_, gameScene);
  635. Button how_to_play_scene(23, 2, 2, 6, how_to_play_, howToPlayScene);
  636. Button change_turn(1, 1, 1, 8, nullstr, changeTurn);
  637.  
  638. Pile p1(14, 1);
  639. Pile p2(28, 2);
  640. Pile p3(42, 3);
  641. Pile p4(56, 4);
  642. Pile p5(70, 5);
  643.  
  644. void game()
  645. {
  646.  
  647. if(cols()>1||sum()>1){
  648. nrCoins[1] = p1.update(mi, mj);//returns the number of
  649. nrCoins[2] = p2.update(mi, mj);//current coins in the pile
  650. nrCoins[3] = p3.update(mi, mj);
  651. nrCoins[4] = p4.update(mi, mj);
  652. nrCoins[5] = p5.update(mi, mj);
  653. }
  654.  
  655. if(updated)
  656. {
  657. turn = 1 - turn;
  658. updated = false;
  659. }
  660.  
  661. change_turn.update();
  662.  
  663. if(restart_game)
  664. {
  665. p1.reset(14, 1);
  666. p2.reset(28, 2);
  667. p3.reset(42, 3);
  668. p4.reset(56, 4);
  669. p5.reset(70, 5);
  670. nrCoins[3]=2;
  671. turn = default_turn;
  672. restart_game=false;
  673. score_updated = false;
  674. }
  675.  
  676. //display
  677. p1.draw(screen);
  678. p2.draw(screen);
  679. p3.draw(screen);
  680. p4.draw(screen);
  681. p5.draw(screen);
  682.  
  683. if(cols()==1&&sum()==1)
  684. {
  685. int i;
  686. if(turn==0)
  687. i = print(player1, 35 + (10 - wstrlen(player1) - 1), 10);
  688. else
  689. i = print(player2, 35 + (10 - wstrlen(player2) - 1), 10);
  690.  
  691. print(won, i);
  692.  
  693. if(score_updated == false)
  694. {
  695. score_updated = true;
  696. if(turn == 0)
  697. ++score1;
  698. else ++score2;
  699. }
  700.  
  701.  
  702. i = print(player1, 31 + (10 - wstrlen(player1) - 1), 12);
  703. i = print(score1, i);
  704. i = print('|', i);
  705. i = print(score2, i);
  706. print(player2, i);
  707. }
  708.  
  709. if(cols()==0)
  710. {
  711. int i = 0;
  712. if(turn==1)
  713. i = print(player1, 35 + (10 - wstrlen(player1) - 1), 10);
  714. else
  715. i = print(player2, 35 + (10 - wstrlen(player2) - 1), 10);
  716.  
  717. print(won, i);
  718.  
  719.  
  720. if(score_updated == false)
  721. {
  722. score_updated = true;
  723. if(turn == 1)
  724. ++score1;
  725. else ++score2;
  726. }
  727.  
  728. i = print(player1, 31 + (10 - wstrlen(player1) - 1), 12);
  729. i = print(score1, i);
  730. i = print('|', i);
  731. i = print(score2, i);
  732. print(player2, i);
  733. }
  734. }
  735.  
  736. void howToPlay()
  737. {
  738.  
  739. }
  740.  
  741. bool __ok = false;
  742. void setOkToTrue(){
  743. __ok = !__ok;
  744. }
  745.  
  746. void dropBox(int ipos, int jpos, int isize, std::vector<wchar_t*>& wlist, wchar_t* output)
  747. {if(!widgets_updated){widgets_updated = true;
  748. COORD c = {(short)jpos, (short)ipos};
  749. std::vector<Button>butons;
  750. for(size_t i = 0; i < wlist.size(); ++i){
  751. butons.push_back(Button(ipos+i*2+3, jpos-2, 1, isize, wlist[i], setOkToTrue));
  752. }
  753. wchar_t add_wchr[10] = L"add name";
  754. Button add(ipos+1, jpos+1, 1, isize-2, add_wchr, setOkToTrue);
  755. int cell_count2 = (wlist.size() * 2 + 3/*aditional empty space*/) * isize;
  756. wchar_t *screen2 = new wchar_t[cell_count2];
  757. bool naming = false;
  758. wchar_t new_name[11] = {0};
  759. unsigned short new_name_iterator = 0;
  760. bool b_held = false;
  761.  
  762. auto print2 = [](wchar_t n[], int linear_pos, wchar_t* scr)
  763. {
  764. int i = 0;
  765. while (n[i] != 0)
  766. {
  767. scr[linear_pos + i] = n[i];
  768. ++i;
  769. }
  770. return linear_pos + i + 1;
  771. };
  772. auto print2xy = [print2, isize](wchar_t n[], int x, int y, wchar_t* scr)
  773. {
  774. int pos = y*isize + x;
  775. return print2(n, pos, scr);
  776. };
  777.  
  778.  
  779. bool loopbool = true;
  780. while(loopbool)//condition
  781. {
  782. //update input information
  783. mouse.update();
  784. keyboard.update();
  785.  
  786. //content
  787. //int namecount = 0;
  788. for(int i = cell_count2 - 1; i >= 0; i--)
  789. screen2[i] = L' ';
  790. for(unsigned i = 0; i < wlist.size() * 2 + 2; ++i)
  791. {
  792. screen2[i * isize] = 9474;
  793. screen2[i * isize + isize - 1] = 9474;
  794. }
  795. for(int i = 0; i < isize; ++i)
  796. {
  797. screen2[cell_count2-i] = 9644;
  798. }
  799.  
  800. screen2[cell_count2-isize]=9492;
  801. screen2[cell_count2-1] = 9496;
  802.  
  803.  
  804. add.update();
  805. if(__ok)
  806. {
  807. naming = true;
  808. testbool = !testbool;
  809. __ok = false;
  810. }
  811. if(!naming)
  812. add.draw(screen2, isize, 1, 1);
  813. else
  814. {
  815. print2xy(new_name, 1, 1, screen2);
  816. if(keyboard.keyPressed() > 0)
  817. {
  818. if(new_name_iterator < 10)new_name[new_name_iterator] = keyboard.keyPressed();
  819. if(new_name_iterator < 11)++new_name_iterator;
  820. }
  821. if(GetKeyState(VK_BACK) < 0)
  822. {
  823. if(!b_held)
  824. {
  825. if(new_name_iterator > 0)--new_name_iterator;
  826. new_name[new_name_iterator] = 0;
  827. b_held = true;
  828. }
  829. } else b_held = false;
  830. }
  831.  
  832. for(unsigned i = 0; i < wlist.size(); i++)
  833. {
  834. if(!naming)butons[i].update();
  835. butons[i].draw(screen2, isize, i*2+3, 1);
  836. if(__ok)
  837. {
  838. int j = 0;
  839. while(wlist[i][j]!=0)
  840. {
  841. output[j] = wlist[i][j];
  842. ++j;
  843. }
  844. output[j] = 0;
  845. __ok = false;
  846. loopbool = false;
  847. }
  848. }
  849.  
  850. if(naming && GetKeyState(VK_RETURN) < 0)
  851. {
  852. naming = false;
  853. wchar_t* nn = new wchar_t[11];
  854. for(size_t i = 0; i < 11; ++i)
  855. nn[i] = new_name[i];
  856. wlist.push_back(nn);
  857. loopbool = false;
  858. for(int i = 0; i < 10; ++i)
  859. output[i] = new_name[i];
  860. }
  861.  
  862. //display
  863. c.Y = (short)ipos;
  864. for(unsigned un = 0; un < wlist.size() * 2 + 3; un++)
  865. {
  866. WriteConsoleOutputCharacter(hConsole, screen2 + un * isize, isize, c, &dwBytesWritten);
  867. c.Y = c.Y + 1;
  868. }
  869. Sleep(1);
  870.  
  871. if(mouse.isClicked() && (mi < ipos - 2 || mi > ipos + cell_count2 / isize - 1 || mj < jpos || mj >= jpos + isize))
  872. loopbool = false;
  873. }
  874. }}
  875.  
  876. std::vector<wchar_t*> names;
  877. void db1()
  878. {
  879. dropBox(4, 30, 13, names, player1);
  880. }
  881. void db2()
  882. {
  883. dropBox(4, 46, 13, names, player2);
  884. }
  885.  
  886. int nrc = 9450;
  887. void nrcpp(){++nrc;}
  888. wchar_t box_wchr[] = {9484, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9488,
  889. 9474, L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' ', L' ', 9660, 9474,
  890. 9492, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9472, 9496, 0};
  891. Button p1_naming_box(2, 30, 3, 13, box_wchr, db1);
  892. Button p2_naming_box(2, 46, 3, 13, box_wchr, db2);
  893.  
  894. void options()
  895. {
  896. print(player_names_wchr, 15, 3);
  897.  
  898. p1_naming_box.update();
  899. p1_naming_box.draw();
  900. print(player1, 31, 3);
  901.  
  902. //print((wchar_t)10563 , 44, 3);
  903.  
  904. p2_naming_box.update();
  905. p2_naming_box.draw();
  906. print(player2, 47, 3);
  907.  
  908. //int pozz = print((wchar_t)nrc, 45, 8);
  909. // print(nrc, pozz);
  910. }
  911.  
  912. //9660 triangle down
  913. //9644 horizontal line
  914. void sideBar()
  915. {
  916. if(keyboard.keyPressed() == 'M')
  917. ++nrc;
  918. //Show who's player's turn is
  919. print(turn_wchr, 2, 0);
  920. if(turn==0)
  921. print(player1, 0, 1);
  922. else
  923. print(player2, 0, 1);
  924.  
  925. //update buttons
  926. new_game.update();
  927. ebutton.update();
  928. options_scene.update();
  929. game_scene.update();
  930. how_to_play_scene.update();
  931.  
  932. //display buttons
  933. new_game.draw();
  934. options_scene.draw();
  935. game_scene.draw();
  936. how_to_play_scene.draw();
  937.  
  938. {//shows which button (scene toggle button) is selected
  939. if (scene == 0)//how to play
  940. {
  941. print((wchar_t)WHITE_SPACE, 0, 23);
  942. print((wchar_t)WHITE_SPACE, 9, 23);
  943.  
  944. print((wchar_t)WHITE_SPACE, 0, 24);
  945. print((wchar_t)WHITE_SPACE, 9, 24);
  946. }
  947. else if (scene == 1)//game scene
  948. {
  949. print((wchar_t)WHITE_SPACE, 0, 19);
  950. print((wchar_t)WHITE_SPACE, 9, 19);
  951. }
  952. else if (scene == 2)//options scene
  953. {
  954. print((wchar_t)WHITE_SPACE, 0, 21);
  955. print((wchar_t)WHITE_SPACE, 9, 21);
  956. }
  957. }
  958.  
  959. //sidebar line
  960. for(int i=0; i<screen_height; i++)
  961. screen[i*screen_width + 10] = WHITE_SPACE;
  962. }
  963.  
  964. int main()
  965. {
  966. //windows 10 compatibility stuff
  967. hwnd = GetConsoleWindow();
  968. updateVersion();
  969.  
  970. //window output set up
  971. hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  972. SetConsoleActiveScreenBuffer(hConsole);
  973.  
  974. //miscellaneous
  975. for (int i = 0; i < 50; ++i)
  976. if (selected_coin_texture[i] == L'#') selected_coin_texture[i] = WHITE_SPACE;
  977. for (int i = 0; i < cell_count; ++i)
  978. screen[i] = L' ';
  979. wchar_t temp[10] = L"Mihai";
  980. names.push_back(temp);
  981. wchar_t temp2[10] = L"Matei";
  982. names.push_back(temp2);
  983. wchar_t temp3[10] = L"Mitca";
  984. names.push_back(temp3);
  985. wchar_t temp4[10] = L"Mihalache";
  986. names.push_back(temp4);
  987.  
  988. while(running)
  989. {
  990. //update input information
  991. mouse.update();
  992. keyboard.update();
  993.  
  994. widgets_updated = false;
  995.  
  996. //clear screen
  997. for(int i = 0; i < cell_count; i++)
  998. screen[i]=L' ';
  999.  
  1000. if (scene == 0)
  1001. howToPlay();
  1002. else if(scene == 1)
  1003. game();
  1004. else if (scene == 2)
  1005. options();
  1006.  
  1007. sideBar();
  1008.  
  1009. if(keyboard.keyPressed()>0)
  1010. testbool = true;
  1011. if(testbool)
  1012. print('k', 6, 12);
  1013.  
  1014. int pozz = print('i', 1, 7);
  1015. pozz = print(mi, pozz);
  1016. pozz = print('j', 1, 8);
  1017. pozz = print(mj, pozz);
  1018.  
  1019. //display
  1020. WriteConsoleOutputCharacter(hConsole, screen, cell_count, zerozero, &dwBytesWritten);
  1021.  
  1022. Sleep(1);
  1023.  
  1024. if(!running)exit(0);
  1025.  
  1026. }
  1027.  
  1028. return 0;
  1029. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement