Hey Leute, habe hier ein Quelltext für TicTacToe Spiel das Problem ist das es noch kein Ergebnis ausgibt.
Ich möchte das sobald 3 Gleiche Symbole in einer Reihe sind ein "KREIS GEWINNT" oder "KREUZ GEWINNT" erscheint... jedoch habe ich keinen Schimmer wie ich dies prüfen lassen kann.
Hoffe könnt mir ne Lösung sagen hier mal der Quellcode:
Mfg Foooxhound
Ich möchte das sobald 3 Gleiche Symbole in einer Reihe sind ein "KREIS GEWINNT" oder "KREUZ GEWINNT" erscheint... jedoch habe ich keinen Schimmer wie ich dies prüfen lassen kann.
Hoffe könnt mir ne Lösung sagen hier mal der Quellcode:
Java:
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TicTacToe extends Frame {
Button[] b = new Button[9];
int i = 1;
public TicTacToe() {
setTitle("TTT - 2012");
setSize(500, 500);
setLayout(new GridLayout(3, 3));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
ActionListener listy = new ActionListener() {
public void actionPerformed(ActionEvent e) {
Button b = (Button) e.getSource();
if (i % 2 == 0) {
b.setLabel("O");
} else {
b.setLabel("X");
}
b.setEnabled(false);
i++;
}
};
Font f = new Font("Comic Sans",0,72);
for (int i = 0; i < 9; i++) {
b[i] = new Button("?");
b[i].addActionListener(listy);
b[i].setFont(f);
add(b[i]);
}
setVisible(true);
}
public static void main(String[] args) {
new TicTacToe();
}
}
Mfg Foooxhound