Advertisement
Guest User

Untitled

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