I'm new here and i'm sory for not my perfect english and for my newbie java problems.
I'm trying to make a simple "Four in row" game but i'm having some problems.
for (int y = 0; y < length; y++) {
for (int x = 0; x < width; x++) {
grid[x][y].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int seznam[] = new int[6];
int y = 1;
if ( ((e.getSource() == grid[0][y]) )
|| ((e.getSource() == grid[1][y]))
|| ((e.getSource() == grid[2][y]))
|| ((e.getSource() == grid[3][y]))
|| ((e.getSource() == grid[4][y]))
|| ((e.getSource() == grid[5][y]))) {
for (int x = 5; x > -1; x--) {
seznam[x] = x;
}
Arrays.sort(seznam);
int n = seznam[seznam.length-1];
if (grid[n][y].getBackground().equals(Color.gray)){
grid[n][y].setBackground(Color.blue);
}
// From here the problems begine
}
}
});
}
}
What I'm trying to do here is that when an user click the second row the last "button" on the bottom became blue, and so on. I guess you guys know how 4inrow works.
The problems is that I tried to do this with while and if loops but with no good results.
Can anyone help me.
Thankyou


Sign In
Create Account


Back to top










