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
|
bool validate(int row, char col, char flag, char block, int size, int count, char move, bool valid)
{
char response;
char QMark = 63;
if (row < 0 || col < 0 || row >= size || col >= size)
{
cout<<" You have entered invalid coordinates! "<<endl<<endl;
return valid=0;// I want the program to return these values if the conditions are met
}
else if(playerMove[row][col] != block && playerMove[row][col] != flag && playerMove[row][col] != QMark && move == 'm' || move == 'M')
{
cout<<"You have already used these coordinates!"<<endl<<endl;
return valid=0;
}
else if(playerMove[row][col] != block && playerMove[row][col] != flag && move == 'f' || move == 'F')
{
cout<<"You have already used these coordinates!"<<endl<<endl;
return valid = 0;
}
else if(move == 'm' && playerMove[row][col] == flag)
{
cout<<"There is a flag on these coordinates, would you like to remove it? (Y \\ N): ";
cin>>response;
cout<<endl;
if(response == 'y')
{
playerMove[row][col] = QMark;
}
return valid=0;
}
else
return valid=1;
}
void userInput(int numberMines, int size, int sizeTwo)
{
char move, block = 178, flag = 70, bomb = 245;
int row, col, count = 0, flagcount = 0;
bool win = false;
bool valid = 1;//I think its something to do with this variable. I have to intitalise it for the program to run.
do
{
displaygrid(size);
cout<<"Please enter column number: ";
while(!(cin >> col))
{
cout<<endl;
cout<<"You must enter a number!"<<endl;
cin.clear();
cin.ignore(1);
cout<<endl;
cout<<"Please enter column number: ";
}
cout<<"please input row number: ";
while(!(cin >> row))
{
cout<<endl;
cout<<"You must enter a number!"<<endl;
cin.clear();
cin.ignore(1);
cout<<endl;
cout<<"please input row number: ";
}
cout<<endl;
cout<<"Please enter F to indicate a bomb position or M for a move: ";
cin>>move;
cout<<endl<<endl;
validate(row, col, flag, block, size, count, move, valid);//This function is called and the i want it to check the players move then return the value of the valid variable.
if (valid==1)
{
count++;
if(move == 'f' || move == 'F')
{
playerMove[row][col] = flag;
count--;
if(valid == 0)
{
count--;
}
if(mines[row][col] == bomb)
{
flagcount++;
}
}
else playerMove[row][col] = mines[row][col];
}
if(count == sizeTwo && flagcount == numberMines)
{
win = true;
}
}
while(win != true && playerMove[row][col] != bomb);
if(win == true)
{
displayLoss(size);
cout<<" YOU WIN! "<<endl<<endl;
}
else if(playerMove[row][col] == bomb)
{
displayLoss(size);
cout<<" GAME OVER! "<<endl<<endl;
}
}
|