My Function always retuns the same

For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:

bool setzen(int x, int y){

if(feld[x][y]!=3){
return mine=false;
}
else{
return mine=true;
}
}
void loeschen(){
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
feld[i][j]=0;
dataGridView1[i,j]->Value="0";
}
}

}

void minen(){

srand((unsigned)time(NULL));
for(int i=0;i<10;i++){
int x=rand()%10;
int y=rand()%10;
feld[x][y]=3;
dataGridView1[x,y]->Value="3";

}

}


private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label2->Text=Convert::ToString("Spieler 1 ist dran");
loeschen();
minen();


}
private: System::Void dataGridView1_CellClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
int y=dataGridView1->CurrentCellAddress.Y;
int x=dataGridView1->CurrentCellAddress.X;



if(spieler=1){
if(mine=true){
label2->Text=Convert::ToString("Spieler 1 hat verloren. Bitte Neues Spiel drücken");

}
else{

}
}

}
};

}



Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.
It would be very nice if someone could help me.
Last edited on
in c++ you need == to check for comparison, = is the assignment operator.
Now it gives me always the other value (bevor it was always true now it is always false).
Its different now but not better but thanks anyway.
Last edited on
I presume setzen() returns true if there is a mine and false if not.

1
2
3
4
5
6
7
8
9
10
11
bool setzen(int x, int y)
{
    if (feld[x][y]!=3)
   {
         return false;
    }
    else
    { 
         return true;
    }
}



or simply
1
2
3
4
bool setzen(int x, int y)
{
    return (feld[x][y]==3);
}
Yes does it
Ok i dont need help anymore i found a solution.
There is now no setzen() i just changed the if( mine==true) with if(feld[x][y]==3) now it works heer the new code (with some other changes):

#pragma endregion


void loeschen(){
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
feld[i][j]=0;
dataGridView1[i,j]->Value="0";
}
}

}

void minen(){

srand((unsigned)time(NULL));
for(int i=0;i<10;i++){
int x=rand()%10;
int y=rand()%10;
feld[x][y]=3;
dataGridView1[x,y]->Value="3";

}

}


private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label2->Text=Convert::ToString("Spieler 1 ist dran");
loeschen();
minen();


}
private: System::Void dataGridView1_CellClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
int y=dataGridView1->CurrentCellAddress.Y;
int x=dataGridView1->CurrentCellAddress.X;



if(spieler==1){
if(feld[x][y]==3){
label2->Text=Convert::ToString("Spieler 1 hat verloren. Bitte Neues Spiel drücken");

}
else{
if(feld[x][y]==0){
label2->Text=Convert::ToString("Spieler 2 ist dran");
spieler=2;
dataGridView1[x,y]->Value="1";
feld[x][y]=1;
}
else{
label2->Text=Convert::ToString("Das Feld ist belegt. Noch mal Spieler 1");
}
}
}
else{
if(feld[x][y]==3){
label2->Text=Convert::ToString("Spieler 2 hat verloren. Bitte Neues Spiel drücken");

}
else{
if(feld[x][y]==0){
label2->Text=Convert::ToString("Spieler 1 ist dran");
spieler=1;
dataGridView1[x,y]->Value="2";
feld[x][y]=2;
}
else{
label2->Text=Convert::ToString("Das Feld ist belegt. Noch mal Spieler 2");
}
}

}

}
};

}

but thanks anyway (i would write a better thanking but my english is shit)
Last edited on
glad it works, your English is better than my German :)
Topic archived. No new replies allowed.