Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "prgm.h"
- using namespace std;
- //populates board with default non-mine char
- void popArray(char& board[][SIZE])
- {
- for(int i = 0; i < SIZE; i++)
- {
- for(int j=0; j < SIZE; j++)
- {
- board[i][j] = '*';
- }
- }
- }
- //displays the board
- void dispArray(char board[][SIZE])
- {
- //number rows
- cout << " 0 1 2 3 4 " << endl;
- cout << " +~~~~~~~~~+" << endl;
- for(int i = 0; i < SIZE; i++)
- {
- cout << i << "| ";
- for(int j =0; j < SIZE; j++)
- {
- cout << " " << board[i][j];
- }
- cout << " |" << endl;
- }
- cout << " +~~~~~~~~~+" << endl;
- }
- // populates board with mines
- void popMine(char& answer[][SIZE], int mines)
- {
- int minecount = 0;
- int row = (rand() %SIZE);
- int col = (rand() %SIZE);
- while(minecount <= mines)
- {
- answer[row][col] = 'X';
- minecount = 0;
- for(int i = 0; i < SIZE; i++)
- {
- for(int j=0; j < SIZE; j++)
- {
- if(answer[i][j] == 'X')
- {
- minecount++;
- }
- }
- }
- row = (rand() %SIZE);
- col = (rand() %SIZE);
- }
- }
- void showMines(char& board[][SIZE], char& answer[][SIZE])
- {
- for(i = 0; i<SIZE; i++)
- {
- for(j = 0; j < SIZE; j++)
- {
- if(answer[i][j]== 'X')
- {
- board[i][j] = 'X';
- }
- }
- }
- }
- bool end(bool loose)
- {
- if(loose == true)
- {
- cout << "YOU LOOSE" << endl;
- return true;
- }
- else
- {
- cout << "YOU WIN!!!" << endl;
- return false;
- }
- }
- bool validCords(char board[][SIZE],int row,int col)
- {
- if(row < SIZE && col < SIZE)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- bool checkTurn(int& turn)
- {
- if(turn < 10)
- {
- turn++;
- return true;
- }
- else
- {
- return false;
- }
- }
- bool checkMine(char board[][SIZE], int row, int col)
- {
- if(board[row][col] == 'X')
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- int countSurounding(char answer[][SIZE],int row,int col)
- {
- int numMines=0
- if(answer[row-1][col-1]=='X')
- {
- numMines++;
- }
- if(answer[row][col-1]=='X')
- {
- numMines++;
- }
- if(answer[row+1][col-1]=='X')
- {
- numMines++;
- }
- if(answer[row-1][col]=='X')
- {
- numMines++;
- }
- if(answer[row+1][col]=='X')
- {
- numMines++;
- }
- if(answer[row-1][col+1]=='X')
- {
- numMines++;
- }
- if(answer[row][col+1]=='X')
- {
- numMines++;
- }
- if(answer[row+1][col+1]=='X')
- {
- numMines++;
- }
- return numMines;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement