Youtube Battleship Videos

  1. Us Battleship Videos
  2. Videos Of Battleships In Action

Rating is available when the video has been rented.

Battleship C++

The example is a video on youtube and here is the link:https://www.youtube.com/watch?v=b-9FK83iZ_8

This is what I have so far. I got some notes on here too, to tryto help make it better and complete it faster.

*What I need help the most is from 'void hideBoat()' andbelow that, but if you see anything that needs to be correted ormissing please let me know so I can fix it with yourhelp.

The program should do the following things and for credit itmust utilize at least 3 functions:

*Correctly print the instructions

*Correctly print the board (excluding the ship)

*Randomly places a ship on the board in a valid position

*Validates the player's input

- Accepts only rows A - E and columns 1 - 5 only

- Does not accept a guess that was made previously

*Allows the player 10 turns to sink the ship

- If the ship is sank in 10 turns the player wins, otherwise,the player loses

- At the end of the game the player can choose to play again andthe game restarts, otherwise, the game is exited

Note: The example in the video displays 'S' where theship is located, this is for demonstration purposes only, myprogram should hide this by not displaying the 'S'characters.

My battleship box isn't exacly like the one on the videobut it is good enough for me so it doesn't need to befixed.

#include 'stdafx.h'

#include

#include

#include

using namespace std;

//Declare Function to print the instructions

void printInstructions();

void clearBoard();

void printBoard();

void hideBoat(); //Alot like set ship

void inputGuess();

bool isSquareOpen(int row, int col); //if the square is open

bool isGameWon();

//Declared the board to be displayed

//above main, it's global, it can be

//referenced throughout this program

const int SIZE = 5;

char displayBoard[SIZE][SIZE];

bool secretBoard[SIZE][SIZE];

int main()

{

srand((unsigned int)time(0));

char response = 'y';

while (response 'y')

{

printInstructions();

clearBoard();

hideBoat(); //hide the treasure in the board

printBoard();

while (!isGameWon())

{

inputGuess();

printBoard();

}

cout << 'Play again? (y/n)';

cin >> response;

}

//Game over

return 0;

}

//Implement the print instructions function

void printInstructions()

{

cout << 'Your goal is to sink the computers ship.'<< endl;

cout << 'The Computers's ship is only 3 spaces long.'<< endl;

cout << 'It is not diagonal.' << endl;

cout << 'Choose a position on the board (example A1).n'<< endl;

cout << 'You have 10 tries to sink the ship.' <<endl;

cout << endl;

}

void printBoard()

{

cout << ' ---------------------' << endl;

char crow = 'A';

for (int row = 0; row < SIZE; row++)

{

cout << crow << ' ' << displayBoard[row][0]<< ' ' <<

displayBoard[row][1] << ' ' <<displayBoard[row][2] << ' ' <<

Youtube Battleship Videos

displayBoard[row][3] << ' ' <<displayBoard[row][4] << ' ';

cout << endl;

cout << ' ---------------------' << endl;

crow++;

}

cout << ' 1 2 3 4 5n' << endl;

}

//Gets called between game play to reset the boards

void clearBoard()

{

for (int row = 0; row < SIZE; row++)

{

for (int col = 0; col < SIZE; col++)

{

displayBoard[row][col] = ' ';

secretBoard[row][col] = false;

}

}

}

? void hideBoat() ?

{

int row = rand() % SIZE; //Generate number between 0 andSIZE

Us Battleship Videos

int col = rand() % SIZE;

secretBoard[row][col] = true;

//The below code is for testing the example only

displayBoard[row][col] = '*';

//What about a ship??

//to represent the direction, generate a random number between 0and 1

//if the random number that represents direction is 0 put theship horizontally

//when the ship is horizontal

//assuming SIZE is 5

//Generate a random row between 0 and SIZE values between 0 and4

//Generate a random col between 0 and SIZE - values between 0and 2

//set secretBoard[row][col] = true, set secretBoard[row][col+1]to true,

//set secretBoard[row][col+2] = true;

//else if the random number that represents direction is 1 putthe ship vertically

//when the ship is horizontal

//assuming SIZE is 5

//Generate a random row between 0 and SIZE - values between 0and 2

//Generate a random col between 0 and SIZE values between 0 and4

//set secretBoard[row][col] = true, set secretBoard[row +1][col] to true,

//set secretBoard[row+2][col] = true;

}

void inputGuess()

{

char crow;

int col;

int row;

cout << 'You have ' << ? << 'guesses remaining.' << endl;

cout << 'Choose a cell: ';

cin >> crow >> col;

//Transpose user entry to 0 based indexes

col--;

Mamta and her children are good to go to control the funds and the bequest – until she discovers that her own one of a kind children don’t favor of nor bolster her activities in tossing their progression sibling out of the house.i have seen film and purchased video casette. Mamta, the second spouse, abhors him, and like Kaikeyi in Ramayana needs the bequest and riches in her children’s names. She and her little girl’s dad in-law, conspire together, and have the eldest child, including his better half and youngster, tossed out of the house. Reema warah. We appreciated the film and felt this is a MUST see for each great family who trust in customary esteems.

row = int(crow - 65);

if (col < 0 col > 2 row < 0 row > 2 !isSquareOpen(row, col))

{

cout << 'Invalid Input. Try again.' << endl;

}

else if (secretBoard[row][col] true)

{

cout << 'Hit!';

displayBoard[row][col] = 'X';

secretBoard[row][col] = false;

}

else

{

Videos Of Battleships In Action

cout << 'Miss!!';

displayBoard[row][col] = 'O';

}

}

bool isSquareOpen(int row, int col) //if the square is open

{

if (displayBoard[row][col] 'O')

return false;

return true;

}

bool isGameWon()

{

for (int row = 0; row < SIZE; row++)

{

for (int col = 0; col < SIZE; col++)

{

if (secretBoard[row][col] true)

{

return false;

}

}

}

return true;

}

Posted :