Advertisement
shaneliang55

final draft

Dec 6th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9. const int Size = 10;
  10. const string symbol1[] = { "_|=|_", "(oxo)", "( o )", "(___)" };
  11. const string symbol2[] = { " A ", " /_\\ ", "/___\\", " |_| " };
  12. const string symbol3[] = { " | ", " _o_ ", "( )", " -w- " };
  13. const string symbol4[] = { " o ", " / \\ ", "/___\\", "[owo]" };
  14. /*
  15. _|=|_ A | o
  16. (oxo) /_\ _o_ / \
  17. ( o ) /___\ ( ) /___\
  18. (___) |_| -w- [owo]
  19. */
  20. HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
  21.  
  22. const int HIGHLIGHT_COLOR = 10; //green
  23. //don't need
  24. /*void displayBoard(string board[Size][Size])
  25. {
  26. for (int row = 0; row < Size; row++)
  27. {
  28. for (int col = 0; col < Size; col++)
  29. {
  30. if (board[row][col] == "A")
  31. {
  32. cout << "A ";
  33. }
  34. else if (board[row][col] == "B")
  35. {
  36. cout << "B ";
  37. }
  38. else if (board[row][col] == "C")
  39. {
  40. cout << "C ";
  41. }
  42. else if (board[row][col] == "D")
  43. {
  44. cout << "D ";
  45. }
  46. }
  47. cout << endl;
  48. }
  49. }
  50. */
  51. //swap function
  52. void swapthem(string board[Size][Size], int x1, int y1, int x2, int y2)
  53. {
  54. string temp = board[y1][x1];
  55. board[y1][x1] = board[y2][x2];
  56. board[y2][x2] = temp;
  57. }
  58. //findMatching
  59. void findMatches(string board[Size][Size])
  60. {
  61. //rows
  62. for (int r = 0; r < Size; r++)
  63. {
  64. int amt = 1;
  65. string current = board[r][0];
  66. for (int c = 1; c < Size; c++)
  67. {
  68. if (board[r][c] == current)
  69. {
  70. amt++;
  71. }
  72. else
  73. {
  74. if (amt >= 3)
  75. {
  76. for (int x = c - 1; x >= c - amt; x--)
  77. board[r][x] = " ";
  78. }
  79. current = board[r][c];
  80. amt = 1;
  81. }
  82. }
  83. if (amt >= 3)
  84. {
  85. for (int x = Size - 1; x > Size -1 - amt; x--)
  86. board[r][x] = " ";
  87. }
  88. }
  89. //columns
  90. for (int c = 0; c < Size; c++)
  91. {
  92. int amt = 1;
  93. string current = board[0][c];
  94. for (int r = 1; r < Size; r++)
  95. {
  96. if (current == board[r][c])
  97. amt++;
  98. else
  99. {
  100. if (amt > 2)
  101. {
  102. for (int y = r - 1; y >= r - amt; y--)
  103. board[y][c] = " ";
  104. }
  105. current = board[r][c];
  106. amt = 1;
  107. }
  108. if (amt > 2)
  109. {
  110. for (int y = Size - 1; y > Size - 1 - amt; y--)
  111. {
  112. board[y][c] = " ";
  113. }
  114. }
  115. }
  116. }
  117. }
  118. /*
  119. bool gravity(string arr[Size][Size])
  120. {
  121. bool move = false;
  122. for (int y = 0; y < Size - 1; y++)
  123. {
  124. for (int j = 0; j < Size; j++)
  125. {
  126. if (arr[y][j] == " ")
  127. continue;
  128. //if you are floating
  129. if (arr[y + 1][j] == " ")
  130. {
  131. move = true;
  132. arr[y + 1][j] = arr[y][j];
  133. arr[y][j] = " ";
  134. }
  135. }
  136. }
  137. return move;
  138. }
  139. */
  140. void winCondition1()
  141. {
  142. cout << "1" << endl;
  143. }
  144. void winCondition2()
  145. {
  146. cout << "2" << endl;
  147. }
  148. void winCondition3()
  149. {
  150. cout << "3" << endl;
  151. }
  152. int main()
  153. {
  154. cout << "Welcome to the Puzzle Game" << endl;
  155.  
  156.  
  157. srand(time(NULL));
  158. /*------------------------------------------------------------*/
  159. string board[Size][Size];
  160. string possible[] = { "A", "B", "C", "D" }; //how to control <3 matches stand together after setting up randomly
  161. for (int row = 0; row < Size; row++)
  162. {
  163. for (int col = 0; col < Size; col++)
  164. board[row][col] = possible[rand() % 4]; //how many characters you gonna use
  165. }
  166.  
  167. unsigned int row = 0; //no reason to have negative selections
  168. unsigned int col = 0;
  169. bool run = true;
  170. string result = "";
  171. while (run)
  172. {
  173. COORD pos;
  174. pos.X = 0;
  175. pos.Y = 0;
  176. SetConsoleCursorPosition(output, pos);
  177.  
  178. SetConsoleTextAttribute(output, 15); //background
  179. system("cls");
  180. for (int i = 0; i < Size; i++)
  181. {
  182. for (int j = 0; j < Size; j++)
  183. {
  184. if (row == i && col == j)
  185. SetConsoleTextAttribute(output, 16 * HIGHLIGHT_COLOR + 8); //highlight color
  186.  
  187. cout << board[i][j] << " ";
  188. SetConsoleTextAttribute(output, 15); //background
  189. }
  190. cout << endl;
  191. }
  192.  
  193. findMatches(board);
  194.  
  195. SetConsoleTextAttribute(output, 15);
  196. cout << endl;
  197. cout << result << endl;
  198. int x = 0;
  199. int y = 0;
  200.  
  201. //using defindMatch to scan 4 direction whether it is a matche or not, put into all f 4
  202. if (GetAsyncKeyState(0x26) && row > 0)//UP
  203. {
  204. row--;
  205. Sleep(50);
  206. }
  207. else if (GetAsyncKeyState(0x28) && row < Size - 1) //DOWN
  208. {
  209. row++;
  210. Sleep(50);
  211. }
  212. else if (GetAsyncKeyState(0x25) && col > 0)//UP
  213. {
  214. col--;
  215. Sleep(50);
  216. }
  217. else if (GetAsyncKeyState(0x27) && col < Size - 1) //DOWN
  218. {
  219. col++;
  220. Sleep(50);
  221. }
  222. else if (GetAsyncKeyState(0x0D)) //Enter 1st character
  223. {
  224. x = col;
  225. y = row;
  226. Sleep(50);
  227. while (run)
  228. {
  229. if (GetAsyncKeyState(0x26) && row > 0)//UP
  230. {
  231. swapthem(board, x, y, x, y - 1);
  232. break;
  233. }
  234. else if (GetAsyncKeyState(0x28) && row < Size - 1) //DOWN
  235. {
  236. swapthem(board, x, y, x, y + 1);
  237. break;
  238. }
  239. else if (GetAsyncKeyState(0x25) && col > 0) //RIGHT
  240. {
  241. swapthem(board, x, y, x - 1, y);
  242. break;
  243. }
  244. else if (GetAsyncKeyState(0x27) && col < Size - 1) //LEFT
  245. {
  246. swapthem(board, x, y, x + 1, y);
  247. break;
  248. }
  249. }
  250. }
  251. Sleep(50);
  252. }
  253. system("Pause");
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement