Youtube Battleship Videos

Posted by admin
Youtube Battleship Videos Average ratng: 4,0/5 8709 votes

Battleship C++

Don't miss any of Entertainment Tonight's Battleship coverage. See more Battleship news, exclusive interviews, photos, and videos from Entertainment Tonight. The Battleships - The Darkness Of The Future. Comments are disabled for this video.

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.

Youtube Battleship Videos

#include 'stdafx.h'

#include

#include

#include

using namespace std;

//Declare Function to print the instructions

Battleship

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

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;

}

}

}

return true;

}

1,437
Offers in-app purchases
You sank my battleship!
The official version of the classic Hasbro board game of naval combat is now on mobile! Challenge other players in Classic Mode or in the all-new Commanders Mode - a fast-paced, strategic and tactical variation. Play with unique naval commanders and use resources to activate powerful special abilities that will secure you a win as you wage war on the high seas.
Hasbro's BATTLESHIP features:
CLASSIC MODE
- Faithful conversion of the classic board game
- Head-to-head combat
- Sink your opponent’s fleet before they sink yours
- Call your shot and fire!
COMMANDERS MODE
- BATTLESHIP with a twist!
- A brand new, more tactical variation of the game
- 3 new core abilities that shake up the strategic possibilities each turn
- Unique special abilities for each Commander
- New ship shapes to improve gameplay and the fun factor
COMMANDERS
- Battle with commanders from throughout the ages
FLEETS
- Each commander’s fleets feature unique and authentic art for each of the many warships! Watch as they come together in an epic clash of civilizations!
ARENAS
- Deploy your fleet to every corner of the world and battle in epic arenas inspired by historical naval battles!
MISSIONS AND RANKS
- Complete missions to earn medals, rank up and become the ultimate commander of the fleet!
SINGLE PLAYER
- Battle against AI Commanders and raise your game before heading into multiplayer!
MULTIPLAYER
- Take on a world of commanders all battling to have the last fleet standing and prove that you have what it takes to conquer the oceans!
Join us in Hasbro's BATTLESHIP now, and set sail for adventure, battle and glory!
BATTLESHIP is a trademark of Hasbro and is used with permission. © 2018 Hasbro. All Rights Reserved.
Collapse
1,437 total
4
2
Read more