void playComputer() {
    QString coord, message, message2, endMessage;
    int x, y;

    cout << "\nThe S's on the grid are your ships" << endl;
    cout << "The O's mark where the computer is guessing on the top grid" << endl;
    cout << "The O's on the lower grid are your guesses" << endl;
    cout << "The X's are the computer's hits on the top grid and your hits on the lower grid" << endl;
    cout << "If you find all 5 computer ships you win." << endl;
    cout << "If the computer finds your 5 ships, you lose." << endl;
    cout << "Alright! All your ships are set in the grid below" << endl;
    cout << "Lets begin. You start. Guess a coordinate where you think an enemy ship is." << endl;
    while (!checkGameOver(player1Grid, player2Grid, endMessage)) {
        clearScreen();
        if (!message.isEmpty())
            cout << message;
        if (!message2.isEmpty())
            cout << message2;
        displayGrid(player1Grid);
        cout << endl;
        displayGrid(player1HitGrid);

        do {
            cin >> coord;
        } while(!checkValidCoord(coord) | !markGuess(player1HitGrid, player2Grid, coord, message));

        do {
            x =rand() % 10;
            y =rand() % 10;
        } while (!markComputerGuess(player1Grid, x, y, message2));
    }
    cout << endMessage;
    return;
}
Esempio n. 2
0
void promptBattleship(QString grid[10][10]) {
    cout << "Enter the coordinate for your Battleship" << endl;
    QString coord;
    do {
        cin >> coord;
    } while (!checkValidCoord(coord) | !placeShip(grid, coord));
    return;
}
Esempio n. 3
0
void promptAircraftCarrier(QString grid[10][10]) {
    cout << "Enter the coordinate for your Aircraft Carrier" << endl;
    QString coord;
    do {
        cin >> coord;
    } while (!checkValidCoord(coord) | !placeShip(grid, coord));
    return;
}
void playFriend() {
    QString coord, coord2, message;
    cout << "\nThe S's on the grid are your ships" << endl;
    cout << "The O's on the top grid mark where " << player1 << " is guessing." << endl;
    cout << "The O's on the bottom grid mark where " << player2 << " is guessing." << endl;
    cout << "The X's represents hits and are marked on the same grids as the O's" << endl;
    cout << "The first person to sink all 5 ships wins" << endl;

    while (!checkGameOver(player1Grid, player2Grid, message)) {
        cout << player1 << " choose a Coordinate to hit." << endl;
        displayGrid(player1HitGrid);
        cout << endl;
        displayGrid(player2HitGrid);

        do {
            cin >> coord;
        } while(!checkValidCoord(coord) | !markGuess(player1HitGrid, player2Grid, coord, message));

        clearScreen();
        if (!message.isEmpty())
            cout << message;
        cout << player2 << " choose a Coordinate to hit." << endl;
        displayGrid(player1HitGrid);
        cout << endl;
        displayGrid(player2HitGrid);

        do {
            cin >> coord2;
        } while (!checkValidCoord(coord2) | !markGuess(player2HitGrid, player1Grid, coord2, message));
        clearScreen();
        if (!message.isEmpty())
            cout << message;
    }

    if (message == "You Win!\n")
        cout << player1 << " wins!" << endl;
    else if (message == "It's a draw!\n")
        cout << message;
    else
        cout << player2 << " wins!" << endl;
}
void promptDestroyer(QString grid[10][10]) {
    cout << "Enter the coordinate for your Destroyer" << endl;
    QString coord;
    do {
        cin >> coord;
    } while (!checkValidCoord(coord) | !placeShip(grid, coord));


    cout << "Enter the second coordinate for your Destroyer" << endl;
    
    QString coord1;
	coord1 = coord;
    do {
        cin >> coord;
    } while (!checkValidCoordDestroyer(coord, coord1) | !placeShip2(grid, coord,coord1));   
    
    
    return;
}
void promptAircraftCarrier(QString grid[10][10]) {
    cout << "Enter the coordinate for your Aircraft Carrier" << endl;
    QString coord;
    do {
        cin >> coord;
    } while (!checkValidCoord(coord) | !placeShip(grid, coord)); //check already existing point in placeShip


    cout << "Enter the second coordinate for your Aircraft Carrier" << endl;
    
    QString coord1;
	coord1 = coord;
    do {
        cin >> coord;
    } while (!checkValidCoordAircraftCarrier(coord, coord1) | !placeShip2(grid, coord,coord1));
    
    
    return;
}