Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	Minesweeper w;
	w.show();
	return a.exec();
}
Ejemplo n.º 2
0
int main()
{
	srand((unsigned)time(NULL));
	Minesweeper playminesweeper;
	playminesweeper.play();
	return 0;
}
Ejemplo n.º 3
0
/**************************************************************
*	Purpose: This function checks for the two ways to win the gaem.
*           The first is if all mines have been marked, and the 
*           second is if all non-mine spaces have been uncovered.
*
*  	   Entry:  An instance of the Minsweeper class.
*
*  	    Exit:  A bool signifying whether the game was won.
****************************************************************/
bool check_for_win(Minesweeper &game)
{
    bool win = false;
    int num_marked_mines = 0;
    int num_uncovered_not_mines = 0;
    int num_not_mines = (game.getRow() * game.getCol()) - game.getNumMines();//This is all the spaces that aren't mines
    for (int row = 0; row < game.getRow(); ++row)
    {
        for (int col = 0; col < game.getCol(); ++col)
        {
            if (game.getMarked(row, col) && game.getMine(row, col))
            {
                ++num_marked_mines;
            }
            if (!game.getCovered(row, col) && !game.getMine(row, col))
            {
                ++num_uncovered_not_mines;
            }
        }
    }
    if (num_marked_mines == game.getNumMines() || num_uncovered_not_mines == num_not_mines)
    {
        win = true;
    }
    return win;
}
Ejemplo n.º 4
0
int main()
{

	char playAgain = 'y';
	do
	{
		srand(time(NULL)); //seeding the random number generator
		Minesweeper game;
		char gameOver = 'n';

		do
		{
			char move;
			int x, y;

			cout << "Enter a move [m]ark, [u]ncover: ";
			cin >> move;
			cout << "Enter a row: ";
			cin >> x;
			cout << "Enter a column: ";
			cin >> y;

			gameOver = game.takeATurn(move, x, y);
		} while (gameOver == 'n');
		playAgain = 'n';
	} while (playAgain == 'y'); //this forces at least a single pass through the loop

	return 0;
}
Ejemplo n.º 5
0
int main()
{
	srand(time(0));
	Minesweeper thisgame;
  	thisgame.Intro();
	thisgame.Placemines();
	thisgame.Countem();
	thisgame.Move();
	return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv){
  Minesweeper obj;
  if (argc == 2 && atoi(argv[1]) == 1 || argc == 1)
    obj.setGameParams(9,9,10);
  else if (argc == 2 && atoi(argv[1]) == 2)
    obj.setGameParams(16,16,40);
  else if (argc == 2 && atoi(argv[1]) == 3)
    obj.setGameParams(16,30,99);
  else{
    if (argc < 4) return 1;
    int row = atoi(argv[1]);
    int col = atoi(argv[2]);
    int mines = atoi(argv[3]);

    if (col >= 9 && mines <= 999 && mines <= row * col)
      obj.setGameParams(row,col,mines);
    else
      return 1;
  }
  if (!obj.initGame()) return 1;
  obj.insertMines();
  obj.insertDigits();
  obj.startGame();
  return 0;
}
Ejemplo n.º 7
0
/**************************************************************
*	Purpose: This functions checks for the losing condition (if
*            a space with a mine has been uncovered).
*
*  	   Entry:  An instance of the Minsweeper class.
*
*  	    Exit:  A bool signifying whether the game was lost.
****************************************************************/
bool check_for_explosion(Minesweeper &game)
{
    bool explosion = false;
    for (int row = 0; row < game.getRow(); ++row)
    {
        for (int col = 0; col < game.getCol(); ++col)
        {
            if (!game.getCovered(row, col) && game.getMine(row, col))
            {
                explosion = true;
            }
        }
    }
    return explosion;
}
Ejemplo n.º 8
0
/**************************************************************
*	Purpose: This function shows the game board by looping 
*            through the rows and calling another function.
*
*  	   Entry:  An instance of the Minesweeper class.
*
*  	    Exit:  None.
****************************************************************/
void showboard(Minesweeper &game)
{
    cout << endl;
    for (int row = 0; row < game.getRow(); ++row)
    {
        showrow(game, row);
        cout << endl;
    }
    cout << endl;
}
Ejemplo n.º 9
0
/**************************************************************
*	Purpose: This function prints a specified row of the board on 
*            the screen, giving each cell's state a symbol.
*
*  	   Entry:  An instance of the Minesweeper class and a row to show.
*
*  	    Exit:  None.
****************************************************************/
void showrow(Minesweeper &game, int row)
{
    for (int col = 0; col < game.getCol(); ++col)
    {
        if (col == 0) cout << ' ';
        if (game.getCovered(row, col))
        {
            cout << "? ";
        }
        else if (game.getMarked(row, col))
        {
            cout << "M ";
        }
        else if (game.getMine(row, col))
        {
            cout << char(178) << ' ';
        }
        else if (game.getSurround(row, col) > 0)
        {
            cout << game.getSurround(row, col) << ' ';
        }
        else
        {
            cout << "O ";
        }
    }
}
Ejemplo n.º 10
0
int main()
{
	cout << "-----------------COUNTING NEAREST NEIGHBOURS-----------------\n";
	Minesweeper obj;
    int size;
	cout << "Enter the size of the array: ";
	cin >> obj.size;
	
	
	//Create a dynamic array
	int **arr = obj.dynamic_arr(obj.size);
	

	//fill the array
	obj.fill(arr);


	//print the array
	cout << "\nThe array entered is:\n";
	obj.print(arr);

	//find the neighbours
	//The possible neighbour combinations
	//		arr[a-1][b-1] | arr[a-1][b] | arr[a-1][b+1]			
	//      arr[a][b-1]   | arr[a][b]   | arr[a][b+1]
	//		arr[a+1][b-1] | arr[a+1][b] | arr[a+1][b+1]
	//
	// Let's consider all the cases,
	// 1. If the element is a corner element, it will have 3 neighbours
	// 2. If the element is a middle element, it will have 8 neighbours
	// 3. If the element is on the side apart from the corner elements, it will have 5 neighbours
	
    // There are 4 cases to be considered. These are listed below.

	//Search each element
	int **arr_f = obj.find(arr);

	
	//print the array
	cout << "\nThe number of neighbours are:\n";
	obj.print(arr_f);

	//deallocate the memory
	delete[] arr_f;
	delete[] arr;

	system("pause");
	return -1;
}
Ejemplo n.º 11
0
int main(){

    int rows, cols;
    int countField = 0;
    Minesweeper mines;
    
    cin>> rows >> cols;
    while( rows != 0 && cols != 0){
        mines.setRows( rows );
        mines.setColumns( cols );
        if( !mines.isValidValues() )
            break;
        countField++;
        mines.fillField();
        mines.createOutput();
        mines.printOutput( countField );
        cin>> rows >> cols;
    }//while
    return 0;
}
Ejemplo n.º 12
0
int main() {
    srand(time(nullptr));

    sf::Font font;
    if (!font.loadFromFile("sansation.ttf")){
        cout << "Did not find the font 'sansation.ttf'" << endl;
        exit(0);
    }


    //cout << "Enter height, width, and number of mines: ";
    int height = 20, width = 30, mines = 60;
    //cin >> height >> width >> mines;

    Minesweeper* game = new Minesweeper(width, height, mines);

    sf::RenderWindow window(sf::VideoMode(width * tile_size, height * tile_size), "Minesweeper", sf::Style::Close);

    cout << "Welcome to Minesweeper!" << endl;
    cout << "Click a tile to open it. Hit ESC or Q to exit, or space to restart" << endl;

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            switch(event.type) {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::KeyPressed:
                switch(event.key.code) {
                case sf::Keyboard::Escape:
                case sf::Keyboard::Q:
                    window.close();
                    break;
                case sf::Keyboard::Space:
                    delete game;
                    game = new Minesweeper(width, height, mines);
                    break;
                }
                break;
            case sf::Event::MouseButtonPressed:
                if (event.mouseButton.button == sf::Mouse::Left && !game->isGameOver()) {
                    int row = event.mouseButton.y / tile_size;
                    int col = event.mouseButton.x / tile_size;

                    game->openTile(row, col);

                    if (game->isGameOver()) {
                        cout << "GAME OVER! Hit ESC or Q to exit, or space to restart" << endl;
                    }
				}
				else if (event.mouseButton.button == sf::Mouse::Right && !game->isGameOver()) {
					int row = event.mouseButton.y / tile_size;
					int col = event.mouseButton.x / tile_size;

					game->markTile(row, col);
				}
                break;
            }
        }

        window.clear();


        for(int row = 0; row < height; ++row) {
            for(int col = 0; col < width; ++col) {
                const int tile_x = col * tile_size, tile_y = row * tile_size;

                sf::RectangleShape tile;
                tile.setSize(sf::Vector2f(tile_size - border_size, tile_size - border_size));
                tile.setFillColor(game->isTileOpen(row, col) ? open_fill_color : closed_fill_color);
                tile.setPosition(tile_x + border_size / 2.0, tile_y + border_size / 2.0);

                window.draw(tile);

                if (game->isTileOpen(row, col) || (game->isGameOver() && game->isTileMine(row, col))
					|| game->isTileMarked(row, col)) {
                    sf::Text text;
                    text.setStyle(sf::Text::Bold);
                    text.setCharacterSize(tile_size / 2.0);

					if (game->isTileMarked(row, col) && !game->isGameOver()) {
						text.setString("X");
						text.setColor(marked_color);
					}
                    else if (game->isTileMine(row, col)) {
                        text.setString("X");
                        text.setColor(mine_color);
					}
                    else {
                        int num_adjacent_mines = game->numAdjacentMines(row, col);
                        if(num_adjacent_mines == 0) continue; // Don't draw 0s
                        text.setString(to_string(num_adjacent_mines));
                        text.setColor(number_colors[num_adjacent_mines]);
                    }

                    text.setFont(font);

                    sf::FloatRect text_rect = text.getLocalBounds();
                    text.setOrigin(text_rect.left + text_rect.width  / 2.0,
                                   text_rect.top  + text_rect.height / 2.0);
                    text.setPosition(tile_x + tile_size / 2.0, tile_y + tile_size / 2.0);

                    window.draw(text);
				}
            }
        }

        window.display();
    }

    delete game;

    return 0;
}
Ejemplo n.º 13
0
Archivo: main.cpp Proyecto: jorgeer/cpp
int main()
{
	srand(time(0));

	int input;
	Minesweeper m;

	while (true)
	{
		m = Minesweeper();
		m.play();
		cout << "Play again? yes = 1, no = 0" << endl;
		cin >> input;
		if (input == 0) break;
	}
	
	

	/*
	int i;

	Matrix m = Matrix(5);
	cout << "Expect identity 5x5" << endl;
	cout << m << endl;
	
	Matrix invalid = Matrix();
	cout << "Expect invalid" << endl;
	cout << invalid << endl;
	
	Matrix allZero = Matrix(3,4);
	cout << "Expect value 0 3x4" << endl;
	cout << allZero << endl;
	
	Matrix three = Matrix(3,4, 3.3);
	cout << "Expect value 3.3 3x4" << endl;
	cout << three << endl;
	
	Matrix six = three + three;
	cout << "Expect value 6.6 3x4" << endl;
	cout << six << endl;
	
	cout << "Expect value 3.3 3x4" << endl;
	six = three;
	cout << six << endl;
	
	Matrix twoInv = Matrix(4,3, 2.2);
	cout << "Expect value ? 3x4" << endl;
	cout << three * twoInv << endl;

	Matrix first = Matrix(2,3);
	Matrix second = Matrix(3, 2);
	for (i = 0; i < 6; i++)
	{
		first.set(i, i+1);
		second.set(i, i+7);
	}
	cout << "first:" << endl << first << endl;
	cout << "second:" << endl << second << endl;
	cout << "Expect value sum 2x3" << endl;
	cout << first * second << endl;

	Matrix a = Matrix(2, 2);
	Matrix b = Matrix(2,2);
	Matrix c = Matrix(2,2);
	for (i = 0; i < 4; i++)
	{
		a.set(i, i+1);
		b.set(i, 4-i);
	}
	c.set(0, 1.0);
	c.set(1, 3.0);
	c.set(2, 1.5);
	c.set(3, 2.0);

	Matrix d = a + b;
	d = d * b - a + c;
	cout << d << endl;


	Vector v = Vector();
	cout << "Expect invalid" << endl;
	cout << v << endl;

	v = Vector(4);
	cout << "Expect valid vector" << endl;
	cout << v << endl;

	v.set(1, 1.0);
	v.set(2, 2.0);
	v.set(3, 3.0);
	v.set(4, 4.0);

	cout << "length: " << v.length() << endl;

	cout << "end" << endl;
	*/
	return 0;
}
Ejemplo n.º 14
0
void uncover(Minesweeper &game, int row, int col)
{
    game.setCovered(row, col, false);
}
Ejemplo n.º 15
0
void mark(Minesweeper &game, int row, int col)
{
    game.setCovered(row, col, false);
    game.setMarked(row, col, true);
}