Youtube Battleship Videos

Posted on  by  admin

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]; Indian songs download.

bool secretBoard[SIZE][SIZE];

int main()

{

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

char response = 'y';

while (response 'y')

{

printInstructions(); Mp4 mobile movie download.

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] << ' ' <<

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

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--;

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

{

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;

}

Dragon age inquisition official patch online. BioWare Blog. A look at story-based gaming. About; Games; Studios. Edmonton; Austin; Careers; News; Products. This page lists patches for Dragon Age: Inquisition and the issues they specifically address. Contents[show] Patch 11 (Oct 5, 2015) Note: Patch only available for pc xboxone ps4 Increased the duration final slides in Trespasser are displayed. Improved stability. Fixed an issue that reduced the. Dragon Age: Inquisition Patch 11 is available for download. This new patch offers a variety of fixes and new enhancements in the game. The patch version 11 for Dragon Age: Inquisition is released now and below you can find out the official patch logs in details. Dragon Age: Inquisition - The Epic Action RPG - On PC, PS4 and Xbox One - EA Official. DRAGON AGE™: INQUISITION Official Trailer – Game of the Year Edition. View All Media. Sign up today to receive the latest Dragon Age news, updates, behind-the-scenes content, offers, and more (including other EA news, products, events,. Game: Dragon Age: Inquisition. When logged in. DAI Community Patch. Download: Manual; 0 of 0. Click merge, choose a location to save the patch out *WARNING* DO NOT OVERWRITE THE OFFICIAL PATCH 7. Wait for the process to complete and move the.

}

}

return true;

}

Coments are closed
Scroll to top