1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
cout << "This is your game board. Ships taking up one spot each will be placed on your game board. You have to shoot all of them down to win. Good luck\n";
string board[7][7] = { { "0 ", "1 ", "2 ", "3 ", "4 ", "5 ", "6 " },
{ "1 ", "O ", "O ", "O ", "O ", "O ", "O " },
{ "2 ", "O ", "O ", "O ", "O ", "O ", "O " },
{ "3 ", "O ", "O ", "O ", "O ", "O ", "O " },
{ "4 ", "O ", "O ", "O ", "O ", "O ", "O " },
{ "5 ", "O ", "O ", "O ", "O ", "O ", "O " },
{ "6 ", "O ", "O ", "O ", "O ", "O ", "O " } };
for (int i = 0; i <= 6; i++)
{
for (int j = 0; j <= 6; j++)
{
cout << board[i][j];
}
cout << endl;
}
int row, column, ships, x = 0, turns = 0, i, * sr, * sc, ships_left;
bool hit = false;
B:
cout << "Enter the amount of ships you want on the board, up to 36. ";
cin >> ships;
if (ships < 0 || ships > 36)
{
cout << "That number is invalid. Make sure to enter a value more than zero and less than 36. ";
goto B;
}
ships_left = ships;
sr = new int[ships];
sc = new int[ships];
C:
for (i = x; i < ships; i++)
{
sc[i] = rand() % 6 + 1;
sr[i] = rand() % 6 + 1;
for (int a = i; a >= 1; a--)
{
if (sc[i] == sc[a] && sr[i] == sr[a])
{
goto C;
}
}
x++;
}
|