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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <iostream>
#include <string>
using namespace std;
string pass(string team)
{
cout << "\nPass the computer to the " << team << " team.\n";
system("PAUSE");
return team;
}
int main()
{
int blue[5][5] =
{
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
};
int red[5][5] =
{
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
};
int blueremaining = 3;
int redremaining = 3;
int x,y;
char start;
int user;
cout << "------------------BATTLEBOAT------------------\n";
while(true){
cout << "To start a new game enter 'N'.\nTo exit program, enter 'X'.\n>";
cin >> start;
switch(start)
{
case 'N':
case 'n':
{
cout << "This is a two player game.\nYou will each set X & Y Positions for your ships.\nYou will then take turns trying to guess the coordinates of the other teams ships.\nThe grid is 4x4, zeros included.\nDecide who is the blue team, and who is the red team.\n\n";
system("PAUSE");
cout << "Pass the computer to the blue team.\n";
cout << "=====BLUE TEAM=====\n";
cout << "Enter X value of 1st ship: ";
cin >> x;
cout << "Enter Y value of 1st ship: ";
cin >> y;
blue[x][y] = 1;
cout << "Enter X value of 2nd ship: ";
cin >> x;
cout << "Enter Y value of 2nd ship: ";
cin >> y;
blue[x][y] = 1;
cout << "Enter X value of 3rd ship: ";
cin >> x;
cout << "Enter Y value of 3rd ship: ";
cin >> y;
blue[x][y] = 1;
cout << "===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\nNo Scrolling Up!\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n";
cout << "\nPass the computer to the red team.\n";
cout << "=====RED TEAM=====\n";
cout << "Enter X value of 1st ship: ";
cin >> x;
cout << "Enter Y value of 1st ship: ";
cin >> y;
red[x][y] = 1;
cout << "Enter X value of 2nd ship: ";
cin >> x;
cout << "Enter Y value of 2nd ship: ";
cin >> y;
red[x][y] = 1;
cout << "Enter X value of 3rd ship: ";
cin >> x;
cout << "Enter Y value of 3rd ship: ";
cin >> y;
red[x][y] = 1;
cout << "===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\nNo Scrolling Up!\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n";
while(blueremaining != 0 | redremaining != 0)
{
pass("blue");
cout << "You still have " << blueremaining << " ships left!\n";
cout << "Enter X value of target: ";
cin >> x;
cout << "Enter Y value of target: ";
cin >> y;
if(red[x][y] != 0)
{
redremaining--;
cout << "Hit! Red team still has " << redremaining << " ships left!\n";
system("PAUSE");
}else{
cout << "Miss! Red team still has " << redremaining << " ships left!\n";
system("PAUSE");
}
cout << "===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\nNo Scrolling Up!\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n===\n";
pass("red");
cout << "You still have " << redremaining << " ships left!\n";
cout << "Enter X value of target: ";
cin >> x;
cout << "Enter Y value of target: ";
cin >> y;
if(red[x][y] != 0)
{
blueremaining--;
cout << "Hit! Blue team still has " << blueremaining << " ships left!\n";
}else{
cout << "Miss! Blue team still has " << blueremaining << " ships left!\n";
}
}if(redremaining == 0){
cout << "\n==================\n==================\n==================\n==================\n==================\n==================\n==================\n==================\aBLUE TEAM WINS!HOORAH!\n";
}else{cout << "\n==================\n==================\n==================\n==================\n==================\n==================\n==================\n==================\aBLUE TEAM WINS!HOORAH!\n";
}
case 'X':
case 'x':
{
break;
}
}
if(start == 'x' | start == 'X'){break;};
}
return 0;
}
|