import java.awt.*;
import java.awt.event.*;
public class test extends Frame {
// Anfang Variablen
static int j=0,i=0,z1=0,z2=0,x=0,g=0,s=1,r=1,u1=0,u2=0,u3=0,u4=0,u5=0,u6=0,u7=0,u8=0;
static int[][] a = new int[8][6];
private Button stop = new Button("Spiel beenden :(");
private Panel pa = new Panel();
private Label l1 = new Label();
static Label[][] labelFeld = new Label[8][6];
private Panel spielfeld = new Panel();
private Button bu1 = new Button();
private Button bu2 = new Button();
private Button bu3 = new Button();
private Button bu4 = new Button();
private Button bu5 = new Button();
private Button bu6 = new Button();
private Button bu7 = new Button();
private Button bu8 = new Button();
// Ende Variablen
//--------------------- SPIELER CHECKS --------------------------------- //
// Feldcheck
public void feldcheck( ) {
if(a[j][i]==1){
z1++;
if (z1==4) {
g=1;
}
}
else {
z1=0;
}
if (a[j][i]==2){
z2++;
if (z2==4) {
g=2;
}
}
else {
z2=0;
}
}
public void check( ) {
//check nach oben
for(j=0;j<8;j++){
for (i=0;i<6;i++){
feldcheck();
if(i==5){
z1=0;
z2=0;
}
}
}
// Check nach rechts!!!!!
for(i=0;i<6;i++) {
for (j=0;j<8;j++){
feldcheck();
if(j==7){
z1=0;
z2=0;
}
}
}
// Check nach rechtsoben !!!!!
for (i=0;i<3;i++){
for (j=0;j<5;j++){
for (x=0;x<6;x++){
i=i+x;
j=j+x;
if (i>5) {
i=5;
}
if (j>7) {
j=7;
}
feldcheck();
}
}
}
//Ende check
// Check nach rechtsunten
for(i=5;i>=0;i--){
for(j=0;j<5;j++){
for(x=0;x<6;x++){
i=i-x;
j=j+x;
if (i<0) {
i=0;
x=10;
z1=0;
z2=0;
}
if (j>7) {
j=7;
x=10;
z1=0;
z2=0;
}
feldcheck();
}
}
}
}
//Ende check
// ----------------------------Ende checks ------------------------------//
public void spaltefuellen( ) {
for (i=0;i<6;i++) {
if (a[j][i]==0){
a[j][i]=s;
i=8;
}
}
}
public void feldschreiben( ) {
spielfeld.setLayout(new GridLayout(7,8,10,10));
for (i=5;i>=0;i--){
for(j=0;j<8;j++){
labelFeld[j][i].setAlignment(Label.CENTER);
labelFeld[j][i].setText(String.valueOf(a[j][i]));
spielfeld.add(labelFeld[j][i]);
}
}
spielfeld.add(bu1);
spielfeld.add(bu2);
spielfeld.add(bu3);
spielfeld.add(bu4);
spielfeld.add(bu5);
spielfeld.add(bu6);
spielfeld.add(bu7);
spielfeld.add(bu8);
add(spielfeld);
}
public test(final String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(final WindowEvent evt) { System.exit(0); } });
final int frameWidth = 600;
final int frameHeight = 400;
setSize(frameWidth, frameHeight);
setLayout(new BorderLayout());
// Anfang Komponenten
l1.setText("Let's play !!! 4 Gewinnt !!!");
l1.setBackground(Color.orange);
l1.setAlignment(Label.CENTER);
add(BorderLayout.NORTH, l1);
for (i=5;i>=0;i--){
for(j=0;j<8;j++){
labelFeld[j][i] = new Label();
}
}
feldschreiben();
stop.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
stopActionPerformed(evt); } });
pa.add(stop);
pa.setBackground(Color.red);
add(BorderLayout.SOUTH,pa);
bu1.setLabel("go !");
bu2.setLabel("go !");
bu3.setLabel("go !");
bu4.setLabel("go !");
bu5.setLabel("go !");
bu6.setLabel("go !");
bu7.setLabel("go !");
bu8.setLabel("go !");
bu1.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu1ActionPerformed(evt); } });
bu2.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu2ActionPerformed(evt); } });
bu3.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu3ActionPerformed(evt); } });
bu4.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu4ActionPerformed(evt); } });
bu5.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu5ActionPerformed(evt); } });
bu6.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu6ActionPerformed(evt); } });
bu7.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu7ActionPerformed(evt); } });
bu8.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
bu8ActionPerformed(evt); } });
// Ende Komponenten
setVisible(true);
}
// Anfang Ereignisprozeduren
public void stopActionPerformed(final ActionEvent evt) {
System.exit(0);
}
public void bu1ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu1.setEnabled(false);
}
else
{
if(u1<6) {
j=0;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u1++;
}
}
public void bu2ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu2.setEnabled(false);
}
else{
if(u2<6){
j=1;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u2++;
}
}
public void bu3ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu3.setEnabled(false);
}
else{
if(u3<6){
j=2;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u3++;
}
}
public void bu4ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu4.setEnabled(false);
}
else{
if(u4<6){
j=3;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u4++;
}
}
public void bu5ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu5.setEnabled(false);
}
else{
if(u5<6){
j=4;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u5++;
}
}
public void bu6ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu6.setEnabled(false);
}
else{
if(u8<6){
j=5;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u8++;
}
}
public void bu7ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu7.setEnabled(false);
}
else{
if(u6<6){
j=6;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u6++;
}
}
public void bu8ActionPerformed(final ActionEvent evt) {
if(g!=0){
bu8.setEnabled(false);
}
else{
if(u7<6){
j=7;
spaltefuellen();
feldschreiben();
check();
if(g!=0) {
l1.setText("Spieler " + g + " hat gewonnen !!!");
}
s=s+r;
r=r*-1;
}
u7++;
}
}
// Ende Ereignisprozeduren
public static void main(final String[] args) {
new test("test");
}
}