Professional Documents
Culture Documents
// 9/27/00
// Program Description : Implements a simplified version of the game
// minesweeper. The user must clear off squares
// one by one, and is not allowed to mark bombs.
// Any time the user hits a bomb, they lose, just
// like the original game. Play will halt if all
// non-bomb squares have been cleared, and the player
// is declared the winner in this situation.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
void printboard(char[][SIDE]);
int numberbombs(int,int,int[][2]);
int domove(char[][SIDE], char[][SIDE], int[][2], int, int, int*);
void getbombs(int[][2]);
void getmove(int*, int*);
int valid(int,int);
int main() {
int totalmoves; // stores the total moves left for the user before they win.
int i,j;
int x,y;
system("PAUSE");
return 0;
}
// Pre-condition: Nada
// Post-condition: x and y will be set to the values of the coordinates that
// the user desires to uncover on the board.
void getmove(int *x,int *y) {
// Read in move.
printf("To enter a move for row 2 column 3 type 2 3\n");
printf("Enter your move, (row column) -> ");
scanf("%d%d", x, y);
// Re-read if invalid.
while (!valid(*x,*y)) {
printf("Sorry those aren't valid coordinates. Please try again.\n");
printf("Enter your move, (row column) -> ");
scanf("%d%d", x, y);
}
}
int i,j;
int i, j, num;
board[row][column]='*';
for (i=0;i<NUMBOMBS;i++)
board[listbombs[i][0]][listbombs[i][1]]='*';
printboard(board);
printf("Sorry, you lose!\n");
return 1;
}
// Take care of the case that the user chooses a square already chosen.
else if (board[row][column]!='_') {
} // end-if num==0
return 0;
} // end else
}
// Pre-conditions: None
// Post-conditions: Returns 1 iff the coordinates given are within the bounds
// of the gameboard.
int valid(int row, int column) {
int i;
int count = 0;
for (i=0;i<NUMBOMBS;i++) {
return count;
}
int i;
int help;
int curbombs[SIDE*SIDE];
help = rand()%(SIDE*SIDE);
bomblist[i][0] = help/SIDE;
bomblist[i][1] = help%SIDE;
i++;
curbombs[help] = 1;
}
}
}