טעות לא ברורה
שלום,
הכל נראה על פניו הגיוני, אבל ישנה טעות בסופו של דבר במקום כלשהו.
אני מזיז "כלי" על המסך, בפעם הראשונה הכל בסדר, בפעם השנייה כבר קיימת בעיה.
מסיבה לא ברורה איפה שסימנתי (X) לא משתנה הצבע של הרקע למרות שהגדרתי שהם יהיו null ועל פי הקוד אם יש null זה משתנה.
public void searchTool(String str, int i, int j)
{
char s=str.charAt(0);
String tool=str.substring(6);
if (tool.equals("soldier"))
{
char right='n';
char right2='n';
char left='n';
char left2='n';
char up='n';
char up2='n';
char down='n';
char down2='n';
if (j+1<=7)
{
right=B.startWith(i, j+1);
if (right!=s)
{
InfoButton info= new InfoButton(i, j+1, buttons[j+1].getBackground());
buttons[j+1].setBackground(Color.red);
a.add(info);
}
}
if (j+2<=7)
{
right2=B.startWith(i, j+2);
if (right2!=s)
{
InfoButton info= new InfoButton(i, j+2, buttons[j+2].getBackground());
buttons[j+2].setBackground(Color.red);
a.add(info);
}
}
if (j-1>=0)
{
left=B.startWith(i, j-1);
if (left!=s)
{
InfoButton info= new InfoButton(i, j-1, buttons[j-1].getBackground());
buttons[j-1].setBackground(Color.red);
a.add(info);
}
}
if (j-2>=0)
{
left2=B.startWith(i, j-2);
if (left2!=s)
{
InfoButton info= new InfoButton(i, j-2, buttons[j-2].getBackground());
buttons[j-2].setBackground(Color.red);
a.add(info);
}
}
if (i+1<=7)
{
down=B.startWith(i+1, j);
if (down!=s)
{
InfoButton info= new InfoButton(i+1, j, buttons[i+1][j].getBackground());
buttons[i+1][j].setBackground(Color.red);
a.add(info);
}
}
if (i+2<=7)
{
down2=B.startWith(i+2, j);
if (down2!=s)
{
InfoButton info= new InfoButton(i+2, j, buttons[i+2][j].getBackground());
buttons[i+2][j].setBackground(Color.red);
a.add(info);
}
}
if (i-1>=0)
{
up=B.startWith(i-1, j);
if (up!=s)
{
InfoButton info= new InfoButton(i-1, j, buttons[i-1][j].getBackground());
buttons[i-1][j].setBackground(Color.red);
a.add(info);
}
}
if (i-2>=0)
{
up2=B.startWith(i-2, j);
if (up2!=s)
{
InfoButton info= new InfoButton(i-2, j, buttons[i-2][j].getBackground());
buttons[i-2][j].setBackground(Color.red);
a.add(info);
}
}
} // soldier
} // searchTool
של B (מאיפה שאני "מגלה" אם זה כלי מיוחד או סתם לחצו על מקום כלשהו בלוח שהוא ריק).
public void Switch (int x1, int y1, int x2, int y2)
{
if(board[x1][y1]==null)
{
board[x1][y1]=board[x2][y2];
board[x2][y2]=null;
}
}
public String getUniqName (String str)
{
char x=str.charAt(2);
char y=str.charAt(6);
int i_x=Character.getNumericValue(x);
int i_y=Character.getNumericValue;
if (board[i_x][i_y]!=null)
return board[i_x][i_y];
return null;
}
public char startWith (int x, int y)
{
if (board[x][y]!=null)
{
char c=board[x][y].charAt(0);
return c;
}
else return 'n';
}
public String whoIs (int x, int y)
{
return board[x][y];
}
תודה רבה.
שלום,
הכל נראה על פניו הגיוני, אבל ישנה טעות בסופו של דבר במקום כלשהו.
אני מזיז "כלי" על המסך, בפעם הראשונה הכל בסדר, בפעם השנייה כבר קיימת בעיה.
מסיבה לא ברורה איפה שסימנתי (X) לא משתנה הצבע של הרקע למרות שהגדרתי שהם יהיו null ועל פי הקוד אם יש null זה משתנה.
public void searchTool(String str, int i, int j)
{
char s=str.charAt(0);
String tool=str.substring(6);
if (tool.equals("soldier"))
{
char right='n';
char right2='n';
char left='n';
char left2='n';
char up='n';
char up2='n';
char down='n';
char down2='n';
if (j+1<=7)
{
right=B.startWith(i, j+1);
if (right!=s)
{
InfoButton info= new InfoButton(i, j+1, buttons[j+1].getBackground());
buttons[j+1].setBackground(Color.red);
a.add(info);
}
}
if (j+2<=7)
{
right2=B.startWith(i, j+2);
if (right2!=s)
{
InfoButton info= new InfoButton(i, j+2, buttons[j+2].getBackground());
buttons[j+2].setBackground(Color.red);
a.add(info);
}
}
if (j-1>=0)
{
left=B.startWith(i, j-1);
if (left!=s)
{
InfoButton info= new InfoButton(i, j-1, buttons[j-1].getBackground());
buttons[j-1].setBackground(Color.red);
a.add(info);
}
}
if (j-2>=0)
{
left2=B.startWith(i, j-2);
if (left2!=s)
{
InfoButton info= new InfoButton(i, j-2, buttons[j-2].getBackground());
buttons[j-2].setBackground(Color.red);
a.add(info);
}
}
if (i+1<=7)
{
down=B.startWith(i+1, j);
if (down!=s)
{
InfoButton info= new InfoButton(i+1, j, buttons[i+1][j].getBackground());
buttons[i+1][j].setBackground(Color.red);
a.add(info);
}
}
if (i+2<=7)
{
down2=B.startWith(i+2, j);
if (down2!=s)
{
InfoButton info= new InfoButton(i+2, j, buttons[i+2][j].getBackground());
buttons[i+2][j].setBackground(Color.red);
a.add(info);
}
}
if (i-1>=0)
{
up=B.startWith(i-1, j);
if (up!=s)
{
InfoButton info= new InfoButton(i-1, j, buttons[i-1][j].getBackground());
buttons[i-1][j].setBackground(Color.red);
a.add(info);
}
}
if (i-2>=0)
{
up2=B.startWith(i-2, j);
if (up2!=s)
{
InfoButton info= new InfoButton(i-2, j, buttons[i-2][j].getBackground());
buttons[i-2][j].setBackground(Color.red);
a.add(info);
}
}
} // soldier
} // searchTool
של B (מאיפה שאני "מגלה" אם זה כלי מיוחד או סתם לחצו על מקום כלשהו בלוח שהוא ריק).
public void Switch (int x1, int y1, int x2, int y2)
{
if(board[x1][y1]==null)
{
board[x1][y1]=board[x2][y2];
board[x2][y2]=null;
}
}
public String getUniqName (String str)
{
char x=str.charAt(2);
char y=str.charAt(6);
int i_x=Character.getNumericValue(x);
int i_y=Character.getNumericValue;
if (board[i_x][i_y]!=null)
return board[i_x][i_y];
return null;
}
public char startWith (int x, int y)
{
if (board[x][y]!=null)
{
char c=board[x][y].charAt(0);
return c;
}
else return 'n';
}
public String whoIs (int x, int y)
{
return board[x][y];
}
תודה רבה.