package main;
import java.awt.Point;
/*
* Logikklasse.
*/
public class BingoCore {
/** Anzahl der durchgefuehrten Spielzuege */
private int steps = 0;
private int[][] field;
public BingoCore() {
this.field = new int[][]{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
}
public int checkWin() {
//Auswertung der felder
// 1. Reihe Horizontal
if ( this.field[0][0] != 0 && this.field[0][0] == this.field[0][1] && this.field[0][1] == this.field[0][2] )
return this.field[0][0];
// 1. Reihe Vertikal
if ( this.field[0][0] != 0 && this.field[0][0] == this.field[1][0] && this.field[1][0] == this.field[2][0] )
return this.field[0][0];
// 2. Reihe Vertikal
else if ( this.field[0][1] != 0 && this.field[0][1] == this.field[1][1] && this.field[1][1] == this.field[2][1] )
return this.field[0][1];
// 3. Reihe Vertikal
else if ( this.field[0][2] != 0 && this.field[0][2] == this.field[1][2] && this.field[1][2] == this.field[2][2] )
return this.field[0][2];
// Diagonale Links
else if ( this.field[0][0] != 0 && this.field[0][0] == this.field[1][1] && this.field[1][1] == this.field[2][2] )
return this.field[0][0];
// Diagonale Rechts
else if ( this.field[0][2] != 0 && this.field[0][2] == this.field[1][1] && this.field[1][1] == this.field[2][0] )
return this.field[0][0];
// Unentschieden
else if ( this.steps == 225 )
return -1;
return 0;
}
public void setTip( int col, int row ) {
if ( this.field[row][col] == 0 ) {
this.field[row][col] = 1;
this.steps++;
} else {
System.err.println( "Spielstein konnte nicht gesetzt werden! [" + row + ":" + col + "]" );
}
}
public Point enemyTake() {
int r=(int)(Math.random()*15);
for ( int i=r; i<this.field.length; i++ ) {
for ( int i2=0; i2<this.field[i].length; i2++ ) {
if ( this.field[i][i2] == 0 ) {
this.field[i][i2] = 2;
this.steps++;
return new Point( i2, i );
}
}
}
return null;
}
}