Abend alle zusammen
Vielleicht kennt jemand von euch das Spiel Gomoku, ich hab es versucht in JAVA zu programieren, hab aber ein Problem, denn das Spiel soll eigentlich enden wenn in einer reiche oder spalte 5 gleiche Symbole sind, das tut es aber nicht, kann mir vielleicht jemanden helfen und sagen wo der fehler ist?
Hoffe ihr könntet mir helfen
Vielleicht kennt jemand von euch das Spiel Gomoku, ich hab es versucht in JAVA zu programieren, hab aber ein Problem, denn das Spiel soll eigentlich enden wenn in einer reiche oder spalte 5 gleiche Symbole sind, das tut es aber nicht, kann mir vielleicht jemanden helfen und sagen wo der fehler ist?
Hoffe ihr könntet mir helfen
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Gomoku extends JApplet // Start-Fenster
{
JTextField rows = new JTextField(""), // Textfelder fuer Eingaben
cols = new JTextField(""); // mit Standard-Werten
static final int BLANK = 0, XX = 1, OO = 2; // Konstanten fuer Feldbelegung
int counter= 0; // Zaehler fuer Gomoku-Fenster
class GomokuDialog extends JDialog // Gomoku als Dialog
{
int turn = XX; // XX ist erst dran
public GomokuDialog(int w, int h) // Konstruktor, w:Weite h:Hoehe
{
setTitle("Gomoku: "+(++counter));// Titel
setSize(w * 100, h * 100); // Dimension
Container cp = getContentPane(); // Fenster-Container
cp.setLayout(new GridLayout(h, w)); // GridLayout
for(int i = 0; i < w * h; i++) // fuer alle Felder:
cp.add(new GomokuButton()); // mit Panel fuellen
setDefaultCloseOperation(DISPOSE_ON_CLOSE);// Schliessoperation
} // end Konstruktor
class GomokuButton extends JPanel // Panel fuer Feld, innere Kl.
{
int state = BLANK; // Feld-Belegung
public GomokuButton() // Konstruktor:
{
addMouseListener(new ML()); // ML wird registriert
}
public void paintComponent(Graphics g) // zum Neuzeichnen
{
super.paintComponent(g); // Methode in Superklasse
int x1 = 0; // x,y-Koordinaten der
int y1 = 0; // Punkte oben links und
int x2 = getSize().width-1; // unten rechts
int y2 = getSize().height-1; // ...
g.drawRect(x1, y1, x2, y2); // Rechteck zeichnen
x1 = x2/4; // x,y-Koordinate
y1 = y2/4; // von innerem Punkt o.l//
int wide= x2/2; // innere Weite,
int high = y2/2; // Hoehe
if(state== XX)
{
g.drawLine(x1, y1, // Zwei Linien fuer X
x1 + wide, y1 + high); // zeichnen
g.drawLine(x1, y1 + high, // ...
x1 + wide, y1); // ...
}
if(state== OO)
{
g.drawOval(x1, y1, // Kreis fuer O
x1 + wide/2, y1 + high/2);// zeichnen
}
} // end paintComponent
class ML extends MouseAdapter
{ // MouseListener, innere Kl.
public void mousePressed(MouseEvent e)
{ // reagiere auf gedrueckteMaus
if(state == BLANK)
{ // wenn Feld leer
state = turn; // Zustand setzen
turn = (turn == XX ? OO : XX);// fuer naechsten Zug
}
if(state == XX)
{
state = XX;
//wenn Feld mit XX belegt, bleibt XX
}
if(state == OO)
{
state = OO;// wenn Feld mit OO belegt, bleibt OO
}
repaint(); // Neuzeichnen
//checkVictory();
}
} // end ML
} // end Gomoku Button
} // end Gomoku Dialog
class BL implements ActionListener
{ // Listener fuer Los-Knopf
public void actionPerformed(ActionEvent e)
{
JDialog d = new GomokuDialog( // Neuer Dialog, nicht modal
Integer.parseInt(cols.getText()),// Weite,
Integer.parseInt(rows.getText()) ); // ... Hoehe in Feldern
d.setVisible(true); // Sichtbarkeit
}
} // end BL
public void CheckVictory()
{
int zeilen = Integer.parseInt(rows.getText());
int spalten = Integer.parseInt(cols.getText());
int [][] tbl = new int [zeilen][spalten];
int score = 0;
boolean draw = false;
boolean XXwins = false;
boolean OOwins = false;
for(score = 0; score < 5; score++)
{
}
if (XXwins == true)
JOptionPane.showMessageDialog(this,"Spieler X hat gewonnen");
if (OOwins == true)
JOptionPane.showMessageDialog(this,"Spieler O hat gewonenn");
if (draw == true)
JOptionPane.showMessageDialog(this,"Leider hat niemand gewonnen");
}
public void init()
{//
Panel p = new Panel(); // Eingabe-Panel
p.setLayout(new GridLayout(2,2)); // 2x2-GridLayout
p.add(new JLabel("Zeilen (min. 5)", JLabel.CENTER)); // Label, Textfelder fuer
p.add(rows); // Zeilen, Spalten
p.add(new JLabel("Spalten (min.5)", JLabel.CENTER));// ...
p.add(cols);// ...
Container cp= getContentPane();// Fenster-Container
cp.add(p, BorderLayout.NORTH);// Eingabe-Paneloben
JButton b = new JButton("Los");// Start-Knopf fuerDialogs:
b.addActionListener(new BL());// AL registrieren
cp.add(b, BorderLayout.SOUTH);// in Container einsetzen
} // end init
public static void main(String[] args)
{
Konsole.run (new Gomoku(), 200, 100); // Konsolenstart
}
} // end Gomoku