Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void trace_diagonal(int minefield[SIZE][SIZE], int row, int column) {
- trace_diagonal_line(minefield, row, column, 0, 0); // top left
- trace_diagonal_line(minefield, row, column, 0, SIZE); // top right
- trace_diagonal_line(minefield, row, column, SIZE, 0); // bottom left
- trace_diagonal_line(minefield, row, column, SIZE, SIZE); // bottom right
- }
- void trace_diagonal_line(int minefield[SIZE][SIZE], int sourceX, int sourceY, int destinationX, int destinationY) {
- int traceStop = 0;
- int srsX = sourceX;
- int srsY = sourceY;
- int dstX = destinationX;
- int dstY = destinationY;
- while ((srsX < SIZE && srsY < SIZE && srsX >= 0 && srsX >= 0) && (traceStop == 0)) {
- if (minefield[srsX][srsY] != HIDDEN_MINE) {
- placeMine(minefield, srsX, srsY, VISIBLE_SAFE);
- }
- int mines = count_in_square(minefield, srsX, srsY, REVEAL_SQUARE_SIZE, HIDDEN_MINE);
- if (mines > 0) {
- traceStop = 1;
- }
- if (srsX > dstX) { // is on left of origin
- srsX--;
- }
- else { // is on right side
- srsX++;
- }
- if (srsY > dstY) { // is on top of origin
- srsY--;
- }
- else { // is on bottom of origin
- srsY++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement