Java- problem z napisaniem programu

0

Witam. Mam za zadanie napisać mini grę. W polu 6x6 (w losowym miejscu) mają wyskoczyć 3 kulki róznych kolorów. Celem jest ułożenie 3 kulek jednego koloru w linii. Jeżeli kulki są ułożone, to program je kasuje, a jeżeli nie są ułożone, to dorzuca kolejne 3. Do tej pory nie udało mi się za wiele napisać. Oto co stworzyłem:

import javax.swing.;
import java.awt.
;
import java.awt.event.;
import java.io.
;

class kulki extends JFrame implements ActionListener {

JMenuBar powitanie = new JMenuBar();
JMenu p1 = new JMenu("NOWA Gra");
JMenu p2 = new JMenu("Zamknij");

JButton b1 = new JButton("");
JButton b2 = new JButton("");
JButton b3 = new JButton("");
JButton b4 = new JButton("");
JButton b5 = new JButton("");
JButton b6 = new JButton("");
JButton b7 = new JButton("");
JButton b8 = new JButton("");
JButton b9 = new JButton("");
JButton b10 = new JButton("");
JButton b11 = new JButton("");
JButton b12 = new JButton("");
JButton b13 = new JButton("");
JButton b14 = new JButton("");
JButton b15 = new JButton("");
JButton b16 = new JButton("");
JButton b17 = new JButton("");
JButton b18 = new JButton("");
JButton b19 = new JButton("");
JButton b20 = new JButton("");
JButton b21 = new JButton("");
JButton b22 = new JButton("");
JButton b23 = new JButton("");
JButton b24 = new JButton("");
JButton b25 = new JButton("");
JButton b26 = new JButton("");
JButton b27 = new JButton("");
JButton b28 = new JButton("");
JButton b29 = new JButton("");
JButton b30 = new JButton("");
JButton b31 = new JButton("");
JButton b32 = new JButton("");
JButton b33 = new JButton("");
JButton b34 = new JButton("");
JButton b35 = new JButton("");
JButton b36 = new JButton("");
String znak = "O";
String[] pole = new String[]{"0","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","31","32","33","34","35","36"};

public kulki() {
super("kulki");

Container cp = getContentPane();
cp.setLayout(new GridLayout(6,6));


powitanie.add(p1);
powitanie.add(p2);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);
b19.addActionListener(this);
b20.addActionListener(this);
b21.addActionListener(this);
b22.addActionListener(this);
b23.addActionListener(this);
b24.addActionListener(this);
b25.addActionListener(this);
b26.addActionListener(this);
b27.addActionListener(this);
b28.addActionListener(this);
b29.addActionListener(this);
b30.addActionListener(this);
b31.addActionListener(this);
b32.addActionListener(this);
b33.addActionListener(this);
b34.addActionListener(this);
b35.addActionListener(this);
b36.addActionListener(this);


cp.add(b1);
cp.add(b2);
cp.add(b3);
cp.add(b4);
cp.add(b5);
cp.add(b6);
cp.add(b7);
cp.add(b8);
cp.add(b9);
cp.add(b10);
cp.add(b11);
cp.add(b12);
cp.add(b13);
cp.add(b14);
cp.add(b15);
cp.add(b16);
cp.add(b17);
cp.add(b18);
cp.add(b19);
cp.add(b20);
cp.add(b21);
cp.add(b22);
cp.add(b23);
cp.add(b24);
cp.add(b25);
cp.add(b26);
cp.add(b27);
cp.add(b28);
cp.add(b29);
cp.add(b30);
cp.add(b31);
cp.add(b32);
cp.add(b33);
cp.add(b34);
cp.add(b35);
cp.add(b36);


setJMenuBar(powitanie);
setSize(210,230);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);



JOptionPane.showMessageDialog(null, "Życzymy powodzenia POWODZENIA", "kulki", JOptionPane.INFORMATION_MESSAGE);

}
public static void random ()
{
Math.random();

}
public void actionPerformed(ActionEvent e) {

}

public boolean win() {
if (pole[1] == znak && pole[2] == znak && pole[3] == znak) { return true; }
if (pole[4] == znak && pole[5] == znak && pole[6] == znak) { return true; }
if (pole[7] == znak && pole[8] == znak && pole[9] == znak) { return true; }
if (pole[1] == znak && pole[4] == znak && pole[7] == znak) { return true; }
if (pole[2] == znak && pole[5] == znak && pole[8] == znak) { return true; }
if (pole[3] == znak && pole[6] == znak && pole[9] == znak) { return true; }
if (pole[1] == znak && pole[5] == znak && pole[9] == znak) { return true; }
if (pole[3] == znak && pole[5] == znak && pole[7] == znak) { return true; }

return false;
}

public void czysc() {
b1.setText(""); pole[1] = "1";
b2.setText(""); pole[2] = "2";
b3.setText(""); pole[3] = "3";
b4.setText(""); pole[4] = "4";
b5.setText(""); pole[5] = "5";
b6.setText(""); pole[6] = "6";
b7.setText(""); pole[7] = "7";
b8.setText(""); pole[8] = "8";
b9.setText(""); pole[9] = "9";
b10.setText(""); pole[1] = "10";
b11.setText(""); pole[1] = "11";
b12.setText(""); pole[2] = "12";
b13.setText(""); pole[3] = "13";
b14.setText(""); pole[4] = "14";
b15.setText(""); pole[5] = "15";
b16.setText(""); pole[6] = "16";
b17.setText(""); pole[7] = "17";
b18.setText(""); pole[8] = "18";
b19.setText(""); pole[9] = "19";
b20.setText(""); pole[1] = "20";
b21.setText(""); pole[1] = "21";
b22.setText(""); pole[2] = "22";
b23.setText(""); pole[3] = "23";
b24.setText(""); pole[4] = "24";
b25.setText(""); pole[5] = "25";
b26.setText(""); pole[6] = "26";
b27.setText(""); pole[7] = "27";
b28.setText(""); pole[8] = "28";
b29.setText(""); pole[9] = "29";
b30.setText(""); pole[1] = "30";
b31.setText(""); pole[1] = "31";
b32.setText(""); pole[2] = "32";
b33.setText(""); pole[3] = "33";
b34.setText(""); pole[4] = "34";
b35.setText(""); pole[5] = "35";
b36.setText(""); pole[6] = "36";

}
public void next() {

}

}

Czy moglibyście mi podpowiedzieć jak zrobić, żeby wyskoczyły kulki? Albo np liczby zamiast nich?? Byłbym bardzo wdzięczny za pomoc. Pozdrawiam

0

Na razie zrobiłeś tak, że jedyne "kulki" jakie wyskoczyły to oczy...

No sorry, ale nie wiem czy znajdziesz śmiałka, który Ci coś pomoże.

Moja skromna, szczera rada: każda linia, która różni się tylko cyferką / liczbą jest powtórzeniem.
Powtórzenia w programowaniu są złe, a zwłaszcza takie, czyli maksymalnie złe.

Mając do wycięcia 100 jednakowych papierowych kółek, wycinał byś każde z osobna?
Mniej więcej taki jest Twój aktualny kod.

Zrób tak żeby nie było żadnych powtórzeń i spróbuj ponownie.
Prawdopodobieństwo otrzymania pomocy zwiększy się wprost proporcjonalnie do ilości usuniętych powtórzeń.

Jak to zrobisz, będzie można pisać o innych kwestiach, np sensu użycia całego stada JButton-ów w tym zadaniu, itd

Pozdrawiam

1 użytkowników online, w tym zalogowanych: 0, gości: 1