public int[] AddMines() { Random rnd=new Random(); int mine_positions[]=new int[20]; int i_counter []=new int[9]; int j_counter[]=new int [9]; int pos=0; for (int i=0; i<10; i++) { int rand_i = rnd.nextInt(9); i_counter[rand_i]++; int rand_j = rnd.nextInt(9); j_counter[rand_j]++; if(i_counter[rand_i]>1&&j_counter[rand_j]>1) { rand_i = rnd.nextInt(9); rand_j = rnd.nextInt(9); } if(pos<20) { mine_positions[pos]=rand_i; mine_positions[pos+1]=rand_j; pos+=2; } } System.out.print(Arrays.toString(mine_positions)); return mine_positions; } public boolean IsMine(int raw, int col) { int pos=0; for (int i=0; i<Raw; i++) { for (int j=0; j<Col; j++) { while(pos<20) { if (mine_array[pos]==raw && mine_array[pos+1]==col) return true; pos+=2; if(pos==19) pos=0; } } } return false; } public void mouseClicked(MouseEvent e) { Button b = (Button) e.getSource(); for (int i=0; i<Raw; i++) { for (int j=0; j<Col; j++) { if(e.getButton()==MouseEvent.BUTTON1) { if (IsMine(i, j) == true) { b.SetIm(mine.getImage()); b.repaint(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)