Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. void trace_diagonal(int minefield[SIZE][SIZE], int row, int column) {
  2. trace_diagonal_line(minefield, row, column, 0, 0); // top left
  3. trace_diagonal_line(minefield, row, column, 0, SIZE); // top right
  4. trace_diagonal_line(minefield, row, column, SIZE, 0); // bottom left
  5. trace_diagonal_line(minefield, row, column, SIZE, SIZE); // bottom right
  6.  
  7. }
  8.  
  9. void trace_diagonal_line(int minefield[SIZE][SIZE], int sourceX, int sourceY, int destinationX, int destinationY) {
  10. int traceStop = 0;
  11. int srsX = sourceX;
  12. int srsY = sourceY;
  13. int dstX = destinationX;
  14. int dstY = destinationY;
  15.  
  16. while ((srsX < SIZE && srsY < SIZE && srsX >= 0 && srsX >= 0) && (traceStop == 0)) {
  17.  
  18. if (minefield[srsX][srsY] != HIDDEN_MINE) {
  19. placeMine(minefield, srsX, srsY, VISIBLE_SAFE);
  20. }
  21.  
  22. int mines = count_in_square(minefield, srsX, srsY, REVEAL_SQUARE_SIZE, HIDDEN_MINE);
  23.  
  24. if (mines > 0) {
  25. traceStop = 1;
  26. }
  27.  
  28. if (srsX > dstX) { // is on left of origin
  29. srsX--;
  30. }
  31. else { // is on right side
  32. srsX++;
  33. }
  34.  
  35. if (srsY > dstY) { // is on top of origin
  36. srsY--;
  37. }
  38. else { // is on bottom of origin
  39. srsY++;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement