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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
using namespace std;
struct FRIGATE
{
int ARMOR;
int MOVE;
int originalMOVE;
int WEAPON;
int RANGE;
string DIRECTION;
string _turn;
string _fire;
string VALUE;
void inputStats()
{
cout << "\nPlease enter amount of armor: ";
cin >> ARMOR;
validateStat(ARMOR, "ARMOR");
cout << "Please enter the speed of your ship: ";
cin >> MOVE;
validateStat(MOVE, "MOVE");
originalMOVE = MOVE;
cout << "Please enter how many weapons on your ship: ";
cin >> WEAPON;
validateStat(WEAPON, "WEAPON");
cout << "Please enter the range of your guns: ";
cin >> RANGE;
validateStat(RANGE, "RANGE");
}
bool validateSum(int paramArmor, int paramMove, int paramWeapon, int paramRange)
{
if ((paramArmor + paramMove + paramWeapon + paramRange) <= 15)
return true;
else
{
cout << "You have entered invalid values.\n Please ensure your ARMOR, MOVE, WEAPON, and RANGE values do not exceed 15.";
inputStats();
return false;
}
}
void validateStat(int value, string stat)
{
if (stat == "ARMOR" || stat == "MOVE" || stat == "RANGE")
{
if (value > 6 || value < 1)
{
cout << "You have entered invalid values. Please enter a/an " + stat + " value between 1 and 6.\n";
cout << "Please enter amount of " + stat + ": ";
cin >> value;
validateStat(value, stat);
}
}
if (stat == "WEAPON")
{
if (value > 4 || value < 1)
{
cout << "You have entered invalid values. Please enter a WEAPON value between 1 and 4.";
cout << "Please enter how many weapons on your ship: ";
cin >> WEAPON;
validateStat(WEAPON, "WEAPON");
}
}
}
void Move()
{
if(MOVE >=1)
{
if(DIRECTION == "")
DIRECTION = "N";
//this is where to tell the user where they are facing, and ask what they'd like to do
cout << "You are currently facing " + DIRECTION+ ". Would you like to move? (Y or N)";
cin >> _turn;
MOVEMENT();
}
}
void MOVEMENT()
{
if (_turn == "Y" || _turn == "y")
{
cout << "Which direction would you like to move? (N, S, E or W)";
cin >> VALUE;
if (VALUE == "N" || VALUE == "S" || VALUE == "E" || VALUE == "W")
{
Turn(VALUE);
}
else
{
cout << "You have entered an invalid entry. Please enter a N, S, E, W." << endl;
MOVEMENT();
}
}
if (_turn == "N" || _turn == "n")
{
cout << "Would you like to fire at your opponent?(Y or N)";
cin >> _fire;
if (_fire == "Y" || _fire == "y")
{
Fire();
}
}
if (_turn != "N" || _turn != "n" || _turn != "Y" || _turn != "y")
{
cout << "You have entered an invalid entry. Please enter a Y or N." << endl;
Move();
}
else
{
cout << "You have no more action points this turn, it is now your opponent's turn.";
}
}
void Turn(string direction)
{
//this is where to determine how many actions (MOVE points) the user or computer has and subtract from that value..
if( VALUE=="N" )
{
//player+=10;
}
if(MOVE>=1)
{
DIRECTION = direction;
MOVE = MOVE-1; //since the user turned, this subtracts 1 point from their move total
cout << "Please perform your next action. You have " << MOVE << " action points left this turn." << endl;
Move();
}
else
{
cout << "You don't have enough action points to allow this action." << endl;
}
}
void Fire()
{
//this is where to determine where the opponent is, if they're in range and next to
//either side of the boat and within range (RANGE) as well as how many times they fire (WEAPONS),
if(MOVE>=1)
{
MOVE = MOVE-1; //since the user turned, this subtracts 1 point from their move total
cout << "Please perform your next action. You have " << MOVE << " action points left this turn.";
Move();
}
else
{
cout << "You don't have enough action points to allow this action.";
}
}
};
|