Ok, so i have reached a point where by the GetShipCoord function is working fine an dandy, however in fixing it ive created YET ANOTHER problem!
This section of code here is just 1 of the 4 cases used, however they are almost identical anyway..
The issue I am now having is that when it calls the GetShipCoord, it works fine first time around, however if any invalid input is given, the GetShipCoord (line 19) function is either... skipped... or idk, it doesnt re run the function when called, and just skips it, continuing with the rest of the code...
See above for the updated GetShipCoord.
If you would like the full shipplacement function let me know, but as i said, either case is pretty much the same as the one before.
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
|
int shipplacement(int &Xshipcoord, int &Yshipcoord)//Algorithm 5
{
int undo=1;
int a=4;
ShipsToPlace=5;
NotValid=false;
char direction;
while(ShipsToPlace !=0)
{
Getshipcoord(Xcoord, Ycoord);
if(!NotValid)
{
--ShipsToPlace;
Displayshipboard(shipboard);
}
NotValid=false;
undo=0;
cout << "You have " << ShipsToPlace+1 << " Ships to place." << endl;
Getshipcoord(Xcoord, Ycoord);
cout << "Which direction would you like your ship to point?" << endl;
cout << "Up (U), Down (D), Left (L) or Right (R)." << endl;
cin >> direction;
switch (direction)
{
case 'L':
{
cout << "You chose to point your ship Left" << endl;
for(a=4; a!=0; a--)
{
++undo;
while (shipboard[Xcoord][Ycoord] =='s')
{
cout << "You cannot place a ship here as a ship is already in this location: " << Xcoord << ", " << Ycoord << endl;
--undo;
NotValid=true;
break;
}
while(Xcoord<0 || Ycoord<0)
{
cout << "Your ship must be within the borders of the battle zone. Ships are 4 coordinates long. " << Xcoord << ", " << Ycoord << endl;
NotValid=true;
break;
}
while(Xcoord>=10 || Ycoord>=10)
{
cout << "Your ship must be within the borders of the battle zone. Ships are 4 coordinates long. " << Xcoord << ", " << Ycoord << endl;
NotValid=true;
break;
}
if(!NotValid)
{
shipboard[Xcoord][Ycoord]='s';
--Xcoord;
cout << "Xcoord: " << Xcoord << " a: " << a << endl;
}
else
{
while(undo!=0)
{
++Xcoord;
shipboard[Xcoord][Ycoord]=' ';
cout << "Xcoord: " << Xcoord << " Undo: " << undo << endl;
--undo;
}
}
}
break;
}
|
Also sorry about the line spacing, it looks neater on my Visual studio, for some reason loads of spaces were added...