Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.64 KB | None | 0 0
  1. // 更改密碼米字號.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <conio.h>
  8. #include <time.h>
  9. #include<windows.h>
  10. #include <Mmsystem.h>
  11. #pragma comment(lib,"winmm.lib")
  12.  
  13. using namespace std;
  14.  
  15. struct USER
  16. {
  17. char name[13];
  18. char passwd[11];
  19. double cash;
  20. int login_count;
  21. int sim_datei;
  22. int hold[5];
  23. };
  24.  
  25. struct STOCK
  26. {
  27. char name[10];
  28. int count;
  29. int *date;
  30. double *open, *high, *low, *close, *adj;
  31. int *vol;
  32. };
  33.  
  34. STOCK read_stock(char name[])
  35. {
  36. STOCK s;
  37. strcpy_s(s.name, name);
  38. char filename[20];
  39. strcpy_s(filename, name);
  40. strcat_s(filename, ".csv");//字串合併
  41. ifstream fin;
  42. fin.open(filename);
  43. s.count = 0;//?
  44. char temp[1000];
  45. while (!fin.eof())//當檔案還沒結尾時
  46. {
  47. fin.getline(temp, 1000);//逐行讀取
  48. s.count++;
  49. }
  50. fin.close();
  51. s.date = new int[s.count];
  52. s.open = new double[s.count];
  53. s.high = new double[s.count];
  54. s.low = new double[s.count];
  55. s.close = new double[s.count];
  56. s.adj = new double[s.count];
  57. s.vol = new int[s.count];
  58. int i;
  59. char tmp;
  60. fin.open(filename);
  61. for (i = 0; i < s.count; i++)
  62. {
  63. fin >> s.date[i];
  64. fin >> tmp;
  65. fin >> s.open[i];
  66. fin >> tmp;
  67. fin >> s.high[i];
  68. fin >> tmp;
  69. fin >> s.low[i];
  70. fin >> tmp;
  71. fin >> s.close[i];
  72. fin >> tmp;
  73. fin >> s.adj[i];
  74. fin >> tmp;
  75. fin >> s.vol[i];
  76. }
  77. fin.close();
  78. return s;
  79. }
  80.  
  81. void delete_stock(STOCK s)
  82. {
  83. delete[] s.vol;
  84. delete[] s.adj;
  85. delete[] s.close;
  86. delete[] s.low;
  87. delete[] s.high;
  88. delete[] s.open;
  89. delete[] s.date;
  90. }
  91.  
  92. void inputName(char name[], int j)
  93. {
  94. char x;
  95. int c = 0, i;
  96. do {
  97. system("cls");
  98. if (j == 1)
  99. cout << "Username: ";
  100. else if (j == 0)
  101. cout << "Password: ";
  102. if (j == 1)
  103. {
  104. for (i = 0; i < c; i++)
  105. cout << name[i];
  106. }
  107. else if (j == 0)
  108. {
  109. for (i = 0; i < c; i++)
  110. cout << "*";
  111. }
  112. x = _getwch();
  113. if (isalnum(x))
  114. {
  115. if (c == 12 && j == 1)
  116. c--;
  117.  
  118. else if (c == 10 && j == 0)
  119. c--;
  120. name[c] = x;
  121. c++;
  122. }
  123. if (x == 8 && c > 0)//8是後退
  124. c--;
  125. } while (x != 13 || c == 0);
  126. name[c] = '\0';
  127. }
  128.  
  129.  
  130. USER login()
  131. {
  132.  
  133. char name1[13];
  134. char passwd1[11];
  135. USER userlist[1000];
  136. int userno, i, j;
  137. ifstream fin;
  138. fin.open("userlist.txt");
  139. fin >> userno;
  140. for (i = 0; i < userno; i++)
  141. {
  142. fin >> userlist[i].name;
  143. fin >> userlist[i].passwd;
  144. fin >> userlist[i].cash;
  145. fin >> userlist[i].login_count;
  146. fin >> userlist[i].sim_datei;
  147. for (j = 0; j < 5; j++)
  148. fin >> userlist[i].hold[j];
  149. }
  150. fin.close();
  151. do {
  152. system("cls");
  153. inputName(name1, 1);
  154. inputName(passwd1, 0);
  155. for (i = 0; i < userno; i++)
  156. {
  157. if (strcmp(userlist[i].name, name1) == 0)
  158. {
  159. if (strcmp(userlist[i].passwd, passwd1) == 0)
  160. {
  161. userlist[i].login_count++;
  162. return userlist[i];
  163. }
  164. else
  165. {
  166. cout << "Incorrect password!!!!!!" << endl;
  167. cout << "Press any key" << endl;
  168. _getwch();
  169. break;
  170. }
  171. }
  172. }
  173. if (i == userno)
  174. {
  175. char passwd2[11];
  176. int len;
  177. cout <<endl<< "Confirm your password: ";
  178. cin >> passwd2;
  179. len = strlen(passwd2);
  180.  
  181. if (strcmp(passwd1, passwd2) == 0)
  182. {
  183. strcpy_s(userlist[userno].name, name1);
  184. strcpy_s(userlist[userno].passwd, passwd1);
  185. userlist[userno].login_count = 1;
  186. userlist[userno].cash = 10000;
  187. userlist[userno].sim_datei = 2;
  188. userlist[userno].hold[0] = 0;
  189. userlist[userno].hold[1] = 0;
  190. userlist[userno].hold[2] = 0;
  191. userlist[userno].hold[3] = 0;
  192. userlist[userno].hold[4] = 0;
  193. ofstream fout;
  194. fout.open("userlist.txt");
  195. fout << userno + 1 << endl;
  196. for (j = 0; j <= userno; j++)
  197. {
  198. fout << userlist[j].name << endl;
  199. fout << userlist[j].passwd << endl;
  200. fout << userlist[j].cash << endl;
  201. fout << userlist[j].login_count << endl;
  202. fout << userlist[j].sim_datei << endl;
  203. fout << userlist[j].hold[0] << " " << userlist[j].hold[1] << " " << userlist[j].hold[2] << " " << userlist[j].hold[3] << " " << userlist[j].hold[4] << endl;
  204. }
  205. fout.close();
  206. return userlist[userno];
  207. }
  208. }
  209. } while (true);
  210. }
  211.  
  212. void mainUI(int select, USER one, STOCK s[])
  213. {
  214. char left[8];
  215. char right[8];
  216. int i;
  217. for (i = 0; i < 8; i++)
  218. {
  219. left[i] = ' ';
  220. right[i] = ' ';
  221. }
  222. left[select] = '[';
  223. right[select] = ']';
  224. system("cls");
  225. cout << endl << endl << endl;
  226. cout << " ╔ ═ ╗ ╔ ╗╔ ╗ ╔ ═ ═ ═ ╗" << endl;
  227. cout << " ║ █║ ╔ ◢◣◢◣╗ ║ ███║" << endl;
  228. cout << " ║ █║ ║ █◥◤█║ ║ █ ═ ╣" << endl;
  229. cout << " ║ █║ ║ █╔ ╗ █║ ║ ███║" << endl;
  230. cout << " ║ █║ ║ █║ ║ █║ ║ █╔ ═ ╝" << endl;
  231. cout << " ╚ ═ ╝ ╚ ═ ╝ ╚ ═ ╝ ╚ ═ ╝" << endl << endl << endl << endl;
  232. cout << " " << one.name << " 您好,今日日期為 " << s[0].date[one.sim_datei] << endl;
  233. cout << " 你目前現金有 " << one.cash << " 元,總資產為 " << one.cash << " 元" << endl;
  234. cout << "=============================================================================" << endl;
  235. cout << " " << left[1] << "1" << right[1] << " 投資決策" << endl;
  236. cout << " " << left[2] << "2" << right[2] << " 數獨遊戲" << endl;
  237. cout << " " << left[3] << "3" << right[3] << " 寂寞聊天室" << endl;
  238. cout << " " << left[4] << "4" << right[4] << " 猜數字" << endl;
  239. cout << " " << left[5] << "5" << right[5] << " 富爸爸" << endl;
  240. cout << " " << left[6] << "6" << right[6] << " 變更密碼" << endl;
  241. cout << " " << left[7] << "7" << right[7] << " 友情贊助" << endl;
  242. cout << " " << left[0] << "0" << right[0] << " 離開系統" << endl;
  243. cout << "=============================================================================" << endl << endl;
  244. }
  245.  
  246. void print(int M[9][9])
  247. {
  248. int r, c;
  249. for (r = 0; r < 9; r++)
  250. {
  251. for (c = 0; c < 9; c++)
  252. {
  253. if (M[r][c] > 0)
  254. cout << M[r][c] << " ";
  255. else
  256. cout << " ";
  257. }
  258. cout << endl;
  259. }
  260. }
  261.  
  262. void updateZ(int Z[9][9][10], int r, int c, int num)
  263. {
  264. int x, y;
  265. for (x = 0; x < 9; x++)
  266. Z[r][x][num] = 0;
  267. for (y = 0; y < 9; y++)
  268. Z[y][c][num] = 0;
  269. for (y = r / 3 * 3; y <= r / 3 * 3 + 2; y++)
  270. {
  271. for (x = c / 3 * 3; x <= c / 3 * 3 + 2; x++)
  272. {
  273. Z[y][x][num] = 0;
  274. }
  275. }
  276. Z[r][c][num] = 1;
  277. }
  278.  
  279. int findZ(int Z[9][9][10], int r, int c)
  280. {
  281. int i, count, num;
  282. count = 0;
  283. for (i = 1; i <= 9; i++)
  284. {
  285. if (Z[r][c][i] == 1)
  286. {
  287. count++;
  288. num = i;
  289. }
  290. }
  291. if (count == 1)
  292. return num;
  293. else
  294. return 0;
  295. }
  296.  
  297. void solve(int Q[9][9], int A[9][9])
  298. {
  299. int Z[9][9][10];
  300. int r, c, i;
  301. for (r = 0; r < 9; r++)
  302. {
  303. for (c = 0; c < 9; c++)
  304. {
  305. if (Q[r][c] > 0)
  306. {
  307. A[r][c] = Q[r][c];
  308. for (i = 1; i <= 9; i++)
  309. Z[r][c][i] = 0;
  310. Z[r][c][Q[r][c]] = 1;
  311. }
  312. else
  313. {
  314. A[r][c] = 0;
  315. for (i = 1; i <= 9; i++)
  316. Z[r][c][i] = 1;
  317. }
  318. }
  319. }
  320. for (r = 0; r < 9; r++)
  321. {
  322. for (c = 0; c < 9; c++)
  323. {
  324. if (Q[r][c] > 0)
  325. {
  326. updateZ(Z, r, c, Q[r][c]);
  327. }
  328. }
  329. }
  330. int flag = 1, num;
  331. while (flag == 1)
  332. {
  333. flag = 0;
  334. for (r = 0; r < 9; r++)
  335. {
  336. for (c = 0; c < 9; c++)
  337. {
  338. if (A[r][c] == 0)
  339. {
  340. num = findZ(Z, r, c);
  341. if (num > 0)
  342. {
  343. flag = 1;
  344. A[r][c] = num;
  345. updateZ(Z, r, c, num);
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352.  
  353. void printUI(int M[9][9], int rs, int cs)
  354. {
  355. int r, c;
  356. for (r = 0; r < 9; r++)
  357. {
  358. for (c = 0; c < 9; c++)
  359. {
  360. if (r == rs && c == cs && M[r][c] > 0)
  361. cout << "[" << M[r][c] << "]";
  362. else if (M[r][c] > 0)
  363. cout << " " << M[r][c] << " ";
  364. else if (r == rs && c == cs && M[r][c] == 0)
  365. cout << "[" << " " << "]";
  366. else
  367. cout << " " << " " << " ";
  368. }
  369. cout << endl;
  370. }
  371. }
  372.  
  373. bool compare(int M[9][9], int M1[9][9])
  374. {
  375. int r, c;
  376. for (r = 0; r < 9; r++)
  377. {
  378. for (c = 0; c < 9; c++)
  379. {
  380. if (M[r][c] != M1[r][c])
  381. return false;
  382. }
  383.  
  384. }
  385. return true;
  386. }
  387. int Sudoku_main()
  388. {
  389. int Q[9][9], a, b;
  390. srand(time(NULL));
  391. ifstream fin;
  392. char filename[] = "Q1.txt";
  393. filename[1] = '1' + rand() % 3;
  394. fin.open(filename);
  395. for (a = 0; a < 9; a++)
  396. {
  397. for (b = 0; b < 9; b++)
  398. fin >> Q[a][b];
  399. }
  400. fin.close();
  401. int A[9][9], A1[9][9];
  402. int r = 0, c = 0;
  403. char x, y;
  404. int i, j;
  405. for (i = 0; i < 9; i++)
  406. {
  407. for (j = 0; j < 9; j++)
  408. {
  409. A[i][j] = Q[i][j];
  410. }
  411. }
  412.  
  413. do {
  414. system("cls");
  415. printUI(A, r, c);
  416. x = _getch();
  417. if (x >= '0'&&x <= '9')
  418. {
  419. if (Q[r][c] == 0)
  420. A[r][c] = x - '0';
  421. }
  422. if (x == -32)
  423. {
  424. y = _getch();
  425. switch (y)
  426. {
  427. case 72:
  428. r = (r + 8) % 9;
  429. break;
  430. case 75:
  431. c = (c + 8) % 9;
  432. break;
  433. case 77:
  434. c = (c + 10) % 9;
  435.  
  436. break;
  437. case 80:
  438. r = (r + 10) % 9;
  439. break;
  440. }
  441. }
  442. } while (x != 13);
  443. solve(Q, A1);
  444. if (compare(A, A1))
  445. {
  446. cout << "Correct" << endl;
  447. _getch();
  448. return 1;
  449. }
  450. else
  451. {
  452. cout << "Try again" << endl;
  453. _getch();
  454. return 0;
  455. }
  456. //return 1 win
  457. //return 0 lose
  458. }
  459.  
  460. void Chat_main(USER one)
  461. {
  462. ifstream fin;
  463. ofstream fout;
  464. char str[1000];
  465. char name[21];
  466. strcpy_s(name, one.name);
  467. do {
  468. system("cls");
  469. fin.open("chat.txt");
  470. while (!fin.eof())
  471. {
  472. fin.getline(str, 1000);
  473. cout << str << endl;
  474. }
  475. fin.close();
  476. cout << "===================================" << endl;
  477. cin.getline(str, 1000);
  478. if (strcmp(str, "EXIT") != 0 && strlen(str) != 0)
  479. {
  480. fout.open("chat.txt", std::ofstream::app);
  481. fout << name << ":" << str << endl;
  482. fout.close();
  483. }
  484. } while (strcmp(str, "EXIT") != 0);
  485.  
  486. }
  487.  
  488. void split(int n, int A[])
  489. {
  490. A[0] = n / 1000;
  491. n %= 1000;
  492. A[1] = n / 100;
  493. n %= 100;
  494. A[2] = n / 10;
  495. A[3] = n % 10;
  496. }
  497.  
  498. int legal(int A[])
  499. {
  500. int out = 1;
  501. int i, j;
  502. if (A[0] >= 10)
  503. return 0;
  504. for (i = 0; i < 3; i++)
  505. {
  506. for (j = i + 1; j < 4; j++)
  507. {
  508. if (A[i] == A[j])
  509. out = 0;
  510. }
  511. }
  512. return out;
  513. }
  514.  
  515. void generate(int A[])
  516. {
  517. //method 3
  518. do {
  519. split(rand() % 10000, A);
  520. } while (legal(A) == 0);
  521. }
  522.  
  523. void input(int G[], int tag)
  524. {
  525. int n;
  526. do {
  527. if (tag == 0)
  528. cout << "Please input your answer:";
  529. else
  530. cout << "Please Guess a number:";
  531.  
  532. cin >> n;
  533. split(n, G);
  534. } while (legal(G) == 0);
  535. }
  536.  
  537. void compare(int G[], int A[], int AB[])
  538. {
  539. int i, j;
  540. AB[0] = 0;
  541. for (i = 0; i < 4; i++)
  542. {
  543. if (G[i] == A[i])
  544. AB[0]++;
  545. }
  546. AB[1] = 0;
  547. for (i = 0; i < 4; i++)
  548. {
  549. for (j = 0; j < 4; j++)
  550. {
  551. if (G[i] == A[j])
  552. AB[1]++;
  553. }
  554. }
  555. AB[1] -= AB[0];//?
  556. }
  557.  
  558. int XAXB_main()
  559. {
  560. int cA[4], hA[4], cG[4], hG[4], cAB[2], hAB[2], tA[4], tAB[2];
  561. int AP[10000], i;
  562. int count = 0;
  563. srand(time(NULL));
  564. generate(cA);
  565. input(hA, 0); // human input hA
  566. for (i = 0; i < 10000; i++)
  567. {
  568. split(i, tA);
  569. if (legal(tA) == 1)
  570. AP[i] = 1;
  571. else
  572. AP[i] = 0;
  573. }
  574. do
  575. {
  576. input(hG, 1);
  577. compare(hG, cA, hAB); //AB[0]->A AB[1]->B
  578. count++;
  579. cout << "(H)" << count << ":" << hAB[0] << "A" << hAB[1] << "B" << endl;
  580. // computer guess -> cG
  581. for (i = 0; i < 10000; i++)
  582. {
  583. if (AP[i] == 1)
  584. {
  585. split(i, cG);
  586. cout << "computer guess:" << cG[0] << cG[1] << cG[2] << cG[3] << endl;
  587. break;
  588. }
  589. }
  590. compare(cG, hA, cAB);
  591. cout << "(C)" << count << ":" << cAB[0] << "A" << cAB[1] << "B" << endl;
  592. //update AP
  593. for (i = 0; i < 10000; i++)
  594. {
  595. if (AP[i] == 1)
  596. {
  597. split(i, tA);
  598. compare(cG, tA, tAB);
  599. if (tAB[0] != cAB[0] || tAB[1] != cAB[1])
  600. AP[i] = 0;
  601. }
  602. }
  603. } while (hAB[0] != 4 && cAB[0] != 4);
  604. _getch(); //
  605. if (hAB[0] == 4 && cAB[0] == 4)
  606. {
  607. cout << "平手" << endl;
  608. _getch();
  609. return 2;
  610. }
  611. else if (hAB[0] == 4)
  612. {
  613. cout << "電腦輸了" << endl;
  614. _getch();
  615. return 1;
  616. }
  617. else
  618. {
  619. cout << "電腦贏了" << endl;
  620. _getch();
  621. return 0;
  622. }
  623. //return 1 win
  624. //return 0 lose
  625. return 0;
  626. }
  627.  
  628. USER Change_password(USER one)
  629. {
  630. int len1,i,len2,j,len3,k;
  631. char passwd1[11];
  632. char passwd2[11];
  633. char passwd3[11];
  634. system("cls");
  635. cout << "password:";
  636. cin >> passwd1;
  637. len1=strlen(passwd1);
  638. do {
  639. system("cls");
  640. cout << "password:";
  641. for (i = 0; i < len1; i++)
  642. {
  643. cout << "*";
  644. }
  645. } while (i<len1);
  646. while (strcmp(one.passwd, passwd1) == 0)
  647. {
  648. cout <<endl<< "new password:";
  649. cin >> passwd2;
  650. len2= strlen(passwd2);
  651. do {
  652. system("cls");
  653. cout << "password:";
  654. for (i = 0; i < len1; i++)
  655. {
  656. cout << "*";
  657. }
  658. } while (i < len1);
  659. cout << endl << "new password:";
  660. for (j = 0; j < len2; j++)
  661. {
  662. cout << "*";
  663. }
  664.  
  665. cout <<endl<< "confirm your password:";
  666. cin >> passwd3;
  667. len3= strlen(passwd3);
  668.  
  669. do {
  670. system("cls");
  671. cout << "password:";
  672. for (i = 0; i < len1; i++)
  673. {
  674. cout << "*";
  675. }
  676. } while (i < len1);
  677. cout << endl << "new password:";
  678. for (j = 0; j < len2; j++)
  679. {
  680. cout << "*";
  681. }
  682. cout << endl << "confirm your password:";
  683. for (k = 0; k < len3; k++)
  684. {
  685. cout << "*";
  686. }
  687. _getwch;
  688. if (strcmp(passwd2, passwd3) == 0)
  689. {
  690. strcpy_s(one.passwd, passwd3);
  691.  
  692. cout << "success" << endl;
  693. break;
  694.  
  695. }
  696. else
  697. break;
  698. }
  699. return one;
  700. }
  701.  
  702. USER Give_money(USER one)
  703. {
  704. double money1,money2;
  705. char name1[15];
  706. char name2[15];
  707. system("cls");
  708. cout << "Who do you want to give money ? :";
  709. cin >> name1;
  710. cout << endl<<"How much do you want to give ? :";
  711. cin >> money1;
  712. if (strcmp(one.name, name1) == 0)
  713. {
  714. one.cash = one.cash + money1;
  715. cout << "success" << endl;
  716.  
  717.  
  718. }
  719. }
  720.  
  721. void SaveUser(USER one)
  722. {
  723. USER userlist[1000];
  724. int userno, i, j;
  725. ifstream fin;
  726. //讀取userlist.txt放入userlist[]中
  727. fin.open("userlist.txt");
  728. fin >> userno;
  729. for (i = 0; i < userno; i++)
  730. {
  731. fin >> userlist[i].name;
  732. fin >> userlist[i].passwd;
  733. fin >> userlist[i].cash;
  734. fin >> userlist[i].login_count;
  735. fin >> userlist[i].sim_datei;
  736. for (j = 0; j < 5; j++)
  737. fin >> userlist[i].hold[j];
  738. if (strcmp(userlist[i].name, one.name) == 0) //讀到目前login的使用者,覆蓋他的資料
  739. {
  740. strcpy_s(userlist[i].passwd, one.passwd);
  741. userlist[i].cash = one.cash;
  742. userlist[i].login_count = one.login_count;
  743. for (j = 0; j < 5; j++)
  744. userlist[i].hold[j] = one.hold[j];
  745. }
  746. }
  747. fin.close();
  748. //更新完後寫回userlist.txt
  749. ofstream fout;
  750. fout.open("userlist.txt");
  751. fout << userno << endl;
  752. for (i = 0; i < userno; i++)
  753. {
  754. fout << userlist[i].name << endl;
  755. fout << userlist[i].passwd << endl;
  756. fout << userlist[i].cash << endl;
  757. fout << userlist[i].login_count << endl;
  758. fout << userlist[i].sim_datei << endl;
  759. fout << userlist[i].hold[0] << " " << userlist[i].hold[1] << " " << userlist[i].hold[2] << " " << userlist[i].hold[3] << " " << userlist[i].hold[4] << endl;
  760. }
  761. fout.close();
  762. }
  763.  
  764. USER investment(USER one, STOCK s[])
  765. {
  766. int i, j;
  767. system("cls");
  768. cout << "Your Cash:" << one.cash << endl;
  769. for (i = 0; i < 5; i++)
  770. {
  771. cout << s[i].name << " ";
  772. for (j = -2; j <= 0; j++)
  773. {
  774. cout << s[i].date[one.sim_datei + j] << " ";
  775. cout << s[i].close[one.sim_datei + j] << " ";
  776. }
  777. cout << "Hold: " << one.hold[i] << endl;
  778. }
  779. char company[10];
  780. do {
  781. cout << "Please tell me which company do you want to invest:" << endl;
  782. cin >> company;
  783. if (strcmp(company, "EXIT") == 0)
  784. break;
  785. else
  786. {
  787. bool ok = true;//是否輸入正確股票名稱
  788. for (i = 0; i < 5; i++)
  789. {
  790. if (strcmp(s[i].name, company) == 0)
  791. {
  792. ok = false;
  793. char x, y;
  794. do {
  795. system("cls");
  796. cout << "Your Cash:" << one.cash << endl;
  797. cout << "Hold: " << one.hold[i] << endl;
  798. cout << "Please press 右鍵 or 左鍵 to change the hold or enter to exit" << endl;
  799. x = _getwch();
  800. if (x == -32)
  801. {
  802. y = _getwch();
  803. switch (y)
  804. {
  805. case 77:
  806.  
  807. if (one.cash >= s[i].close[one.sim_datei])
  808. {
  809. one.hold[i]++;
  810. one.cash -= s[i].close[one.sim_datei];
  811. }
  812. break;
  813. case 75:
  814. if (one.hold[i] > 0)
  815. {
  816. one.hold[i]--;
  817. one.cash += s[i].close[one.sim_datei];
  818. }
  819. break;
  820. }
  821. }
  822. } while (x != 13);
  823. }
  824. }
  825. if (ok)
  826. cout << "!!!!!!!!!! Wrong !!!!!!!!!!" << endl;
  827.  
  828. }
  829. } while (true);
  830. //_getwch();
  831. return one;
  832. }
  833.  
  834. void play()
  835. {
  836. PlaySound(TEXT("汪蘇瀧小星星.wav"), NULL, SND_FILENAME | SND_ASYNC);
  837. }
  838.  
  839. int main()
  840. {
  841. play();
  842. USER one;
  843. STOCK s[5];
  844. s[0] = read_stock("AAPL");
  845. s[1] = read_stock("AMZN");
  846. s[2] = read_stock("FB");
  847. s[3] = read_stock("GOOGL");
  848. s[4] = read_stock("MSFT");
  849. one = login();
  850. int select = 1;
  851. char c1, c2;
  852. do
  853. {
  854. mainUI(select, one, s);
  855. c1 = _getch();
  856. if (c1 == -32)
  857. {
  858. c2 = _getch();
  859. if (c2 == 72)
  860. select = (select + 6) % 7;
  861. if (c2 == 80)
  862. select = (select + 1) % 7;
  863. if (c2 == 77)
  864. c1 = 13;
  865. }
  866. if (c1 >= '0'&&c1 <= '6')
  867. select = c1 - '0';
  868. if (c1 == 13)
  869. {
  870. if (select == 1) //投資決策
  871. {
  872. one = investment(one, s);
  873. }
  874. else if (select == 2) //數獨
  875. {
  876. int win = Sudoku_main();
  877. if (win == 1)
  878. one.cash += 5000;
  879. else
  880. one.cash -= 5000;
  881. }
  882. else if (select == 3) //聊天室
  883. {
  884. Chat_main(one);
  885. }
  886. else if (select == 4) //猜數字
  887. {
  888. int win = XAXB_main();
  889. if (win == 1)
  890. one.cash += 5000;
  891. else if (win == 0)
  892. one.cash += 1000;
  893. else
  894. one.cash -= 100;
  895. }
  896. else if (select == 5) //富爸爸
  897. {
  898. one.cash += 1000;
  899. }
  900. else if (select == 6) //變更密碼
  901. {
  902. one = Change_password(one);
  903. }
  904. else // select == 0
  905. {
  906. break;
  907. }
  908. }
  909. } while (true);
  910. SaveUser(one); //把user狀態存回userlist.txt
  911. delete_stock(s[0]);
  912. delete_stock(s[1]);
  913. delete_stock(s[2]);
  914. delete_stock(s[3]);
  915. delete_stock(s[4]);
  916. return 0;
  917. }
  918. // 執行程式: Ctrl + F5 或 [偵錯] > [啟動但不偵錯] 功能表
  919. // 偵錯程式: F5 或 [偵錯] > [啟動偵錯] 功能表
  920.  
  921. // 開始使用的秘訣:
  922. // 1. 使用 [方案總管] 視窗,新增/管理檔案
  923. // 2. 使用 [Team Explorer] 視窗,連線到原始檔控制
  924. // 3. 使用 [輸出] 視窗,參閱組建輸出與其他訊息
  925. // 4. 使用 [錯誤清單] 視窗,檢視錯誤
  926. // 5. 前往 [專案] > [新增項目],建立新的程式碼檔案,或是前往 [專案] > [新增現有項目],將現有程式碼檔案新增至專案
  927. // 6. 之後要再次開啟此專案時,請前往 [檔案] > [開啟] > [專案],然後選取 .sln 檔案
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement