Advertisement
Guest User

func.cpp

a guest
May 3rd, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include "prgm.h"
  2. using namespace std;
  3. //populates board with default non-mine char
  4. void popArray(char& board[][SIZE])
  5. {
  6. for(int i = 0; i < SIZE; i++)
  7. {
  8. for(int j=0; j < SIZE; j++)
  9. {
  10. board[i][j] = '*';
  11. }
  12. }
  13. }
  14.  
  15. //displays the board
  16. void dispArray(char board[][SIZE])
  17. {
  18. //number rows
  19. cout << " 0 1 2 3 4 " << endl;
  20. cout << " +~~~~~~~~~+" << endl;
  21.  
  22. for(int i = 0; i < SIZE; i++)
  23. {
  24. cout << i << "| ";
  25. for(int j =0; j < SIZE; j++)
  26. {
  27. cout << " " << board[i][j];
  28. }
  29. cout << " |" << endl;
  30. }
  31. cout << " +~~~~~~~~~+" << endl;
  32. }
  33.  
  34.  
  35.  
  36. // populates board with mines
  37. void popMine(char& answer[][SIZE], int mines)
  38. {
  39. int minecount = 0;
  40. int row = (rand() %SIZE);
  41. int col = (rand() %SIZE);
  42. while(minecount <= mines)
  43. {
  44. answer[row][col] = 'X';
  45. minecount = 0;
  46. for(int i = 0; i < SIZE; i++)
  47. {
  48. for(int j=0; j < SIZE; j++)
  49. {
  50. if(answer[i][j] == 'X')
  51. {
  52. minecount++;
  53. }
  54. }
  55. }
  56.  
  57. row = (rand() %SIZE);
  58. col = (rand() %SIZE);
  59. }
  60. }
  61.  
  62. void showMines(char& board[][SIZE], char& answer[][SIZE])
  63. {
  64. for(i = 0; i<SIZE; i++)
  65. {
  66. for(j = 0; j < SIZE; j++)
  67. {
  68. if(answer[i][j]== 'X')
  69. {
  70. board[i][j] = 'X';
  71. }
  72. }
  73. }
  74.  
  75. }
  76.  
  77.  
  78. bool end(bool loose)
  79. {
  80. if(loose == true)
  81. {
  82. cout << "YOU LOOSE" << endl;
  83. return true;
  84. }
  85. else
  86. {
  87. cout << "YOU WIN!!!" << endl;
  88. return false;
  89. }
  90. }
  91.  
  92. bool validCords(char board[][SIZE],int row,int col)
  93. {
  94. if(row < SIZE && col < SIZE)
  95. {
  96. return true;
  97. }
  98. else
  99. {
  100. return false;
  101. }
  102. }
  103.  
  104. bool checkTurn(int& turn)
  105. {
  106. if(turn < 10)
  107. {
  108. turn++;
  109. return true;
  110. }
  111. else
  112. {
  113. return false;
  114. }
  115. }
  116.  
  117. bool checkMine(char board[][SIZE], int row, int col)
  118. {
  119. if(board[row][col] == 'X')
  120. {
  121. return true;
  122. }
  123. else
  124. {
  125. return false;
  126. }
  127. }
  128.  
  129.  
  130. int countSurounding(char answer[][SIZE],int row,int col)
  131. {
  132. int numMines=0
  133. if(answer[row-1][col-1]=='X')
  134. {
  135. numMines++;
  136. }
  137. if(answer[row][col-1]=='X')
  138. {
  139. numMines++;
  140. }
  141. if(answer[row+1][col-1]=='X')
  142. {
  143. numMines++;
  144. }
  145. if(answer[row-1][col]=='X')
  146. {
  147. numMines++;
  148. }
  149. if(answer[row+1][col]=='X')
  150. {
  151. numMines++;
  152. }
  153. if(answer[row-1][col+1]=='X')
  154. {
  155. numMines++;
  156. }
  157. if(answer[row][col+1]=='X')
  158. {
  159. numMines++;
  160. }
  161. if(answer[row+1][col+1]=='X')
  162. {
  163. numMines++;
  164. }
  165. return numMines;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement