import Prog1Tools.*;
public class Tic4 {
public static void main (String[] args) {
go();
}
public static void go ( ) {
//Initialisierung
String a1=" ";
String a2=" ";
String a3=" ";
String b1=" ";
String b2=" ";
String b3=" ";
String c1=" ";
String c2=" ";
String c3=" ";
int S1=0;
int S2=0;
int A=0;
int G1=0;
int G2=0;
//Anleitung
System.out.println("****************************TIC-TAC-TOE******************************");
System.out.println("** ANLEITUNG: **");
System.out.println("** **");
System.out.println("** Gegeben ist folgendes Feld mit 9 nummerierten Feldern: **");
System.out.println("** **");
System.out.println("** 1 |2 |3 **");
System.out.println("** -- -- -- **");
System.out.println("** 4 |5 |6 **");
System.out.println("** -- -- -- **");
System.out.println("** 7 |8 |9 **");
System.out.println("** **");
System.out.println("** Ihr koennt nun abwechselnd eure Felder waehlen. **");
System.out.println("** Gewonnen hat der Spieler, der zuerst 3 Felder hintereinander: **");
System.out.println("** -Senkrecht **");
System.out.println("** -Waagrecht **");
System.out.println("** -Diagonal **");
System.out.println("** gesetzt hat. **");
System.out.println("** Viel Spass beim Spielen von TIC-TAC-TOE: **");
System.out.println("*********************************************************************");
System.out.println("");
System.out.println("DAS SPIEL BEGINNT:");
System.out.println("");
//Schleife
do {
//Abfrage Kreuz
S1=IOTools.readInteger("Kreuz, waehle ein Feld: ");
if ( S1==1 ) {
if ( a1==" " ) {
a1="X";
}
}
if ( S1==2 ) {
if ( a2==" " ) {
a2="X";
}
}
if ( S1==3 ) {
if ( a3==" " ) {
a3="X";
}
}
if ( S1==4 ) {
if ( b1==" " ) {
b1="X";
}
}
if ( S1==5 ) {
if ( b2==" " ) {
b2="X";
}
}
if ( S1==6 ) {
if ( b3==" " ) {
b3="X";
}
}
if ( S1==7 ) {
if ( c1==" " ) {
c1="X";
}
}
if ( S1==8 ) {
if ( c2==" " ) {
c2="X";
}
}
if ( S1==9 ) {
if ( c3==" " ) {
c3="X";
}
}
//Anzeige
System.out.println("\n"+a1+" |"+a2+" |"+a3+" 1 |2 |3");
System.out.println("-- -- -- -- -- --");
System.out.println(b1+" |"+b2+" |"+b3+" 4 |5 |6");
System.out.println("-- -- -- -- -- --");
System.out.println(c1+" |"+c2+" |"+c3+" 7 |8 |9\n");
//Kontrolle X
if ( a1=="X" ) {
if ( a2=="X" ) {
if (a3=="X" ) {
G1=1;
A=1;
}
}
}
if ( b1=="X" ) {
if ( b2=="X" ) {
if (b3=="X" ) {
G1=1;
A=1;
}
}
}
if ( c1=="X" ) {
if ( c2=="X" ) {
if (c3=="X" ) {
G1=1;
A=1;
}
}
}
if ( a1=="X" ) {
if ( b1=="X" ) {
if (c1=="X" ) {
G1=1;
A=1;
}
}
}
if ( a2=="X" ) {
if ( b2=="X" ) {
if (c2=="X" ) {
G1=1;
A=1;
}
}
}
if ( a3=="X" ) {
if ( b3=="X" ) {
if (c3=="X" ) {
G1=1;
A=1;
}
}
}
if ( a1=="X" ) {
if ( b2=="X" ) {
if (c3=="X" ) {
G1=1;
A=1;
}
}
}
if ( a3=="X" ) {
if ( b2=="X" ) {
if (c1=="X" ) {
G1=1;
A=1;
}
}
}
// Kontrolle O
if ( a1=="O" ) {
if ( a2=="O" ) {
if (a3=="O" ) {
G2=1;
A=1;
}
}
}
if ( b1=="O" ) {
if ( b2=="O" ) {
if (b3=="O" ) {
G2=1;
A=1;
}
}
}
if ( c1=="O" ) {
if ( c2=="O" ) {
if (c3=="O" ) {
G2=1;
A=1;
}
}
}
if ( a1=="O" ) {
if ( b1=="O" ) {
if (c1=="O" ) {
G2=1;
A=1;
}
}
}
if ( a2=="O" ) {
if ( b2=="O" ) {
if (c2=="O" ) {
G2=1;
A=1;
}
}
}
if ( a3=="O" ) {
if ( b3=="O" ) {
if (c3=="O" ) {
G2=1;
A=1;
}
}
}
if ( a1=="O" ) {
if ( b2=="O" ) {
if (c3=="O" ) {
G2=1;
A=1;
}
}
}
if ( a3=="O" ) {
if ( b2=="O" ) {
if (c1=="O" ) {
G2=1;
A=1;
}
}
}
//Kontrolle Unentschieden
if ( a1!=" " ) {
if ( a2!=" " ) {
if ( a3!=" " ) {
if ( b1!=" " ) {
if ( b2!=" " ) {
if ( b3!=" " ) {
if ( c1!=" " ) {
if ( c2!=" " ) {
if ( c3!=" " ) {
A=1;
}
}
}
}
}
}
}
}
}
if ( A!=1 ) {
//Abfrage Kreis
S2=IOTools.readInteger("Kreis, waehle ein Feld: ");
if ( S2==1 ) {
if ( a1==" " ) {
a1="O";
}
}
if ( S2==2 ) {
if ( a2==" " ) {
a2="O";
}
}
if ( S2==3 ) {
if ( a3==" " ) {
a3="O";
}
}
if ( S2==4 ) {
if ( b1==" " ) {
b1="O";
}
}
if ( S2==5 ) {
if ( b2==" " ) {
b2="O";
}
}
if ( S2==6 ) {
if ( b3==" " ) {
b3="O";
}
}
if ( S2==7 ) {
if ( c1==" " ) {
c1="O";
}
}
if ( S2==8 ) {
if ( c2==" " ) {
c2="O";
}
}
if ( S2==9 ) {
if ( c3==" " ) {
c3="O";
}
}
//Anzeige
System.out.println("\n"+a1+" |"+a2+" |"+a3+" 1 |2 |3");
System.out.println("-- -- -- -- -- --");
System.out.println(b1+" |"+b2+" |"+b3+" 4 |5 |6");
System.out.println("-- -- -- -- -- --");
System.out.println(c1+" |"+c2+" |"+c3+" 7 |8 |9\n");
}
//Kontrolle X
if ( a1=="X" ) {
if ( a2=="X" ) {
if (a3=="X" ) {
G1=1;
A=1;
}
}
}
if ( b1=="X" ) {
if ( b2=="X" ) {
if (b3=="X" ) {
G1=1;
A=1;
}
}
}
if ( c1=="X" ) {
if ( c2=="X" ) {
if (c3=="X" ) {
G1=1;
A=1;
}
}
}
if ( a1=="X" ) {
if ( b1=="X" ) {
if (c1=="X" ) {
G1=1;
A=1;
}
}
}
if ( a2=="X" ) {
if ( b2=="X" ) {
if (c2=="X" ) {
G1=1;
A=1;
}
}
}
if ( a3=="X" ) {
if ( b3=="X" ) {
if (c3=="X" ) {
G1=1;
A=1;
}
}
}
if ( a1=="X" ) {
if ( b2=="X" ) {
if (c3=="X" ) {
G1=1;
A=1;
}
}
}
if ( a3=="X" ) {
if ( b2=="X" ) {
if (c1=="X" ) {
G1=1;
A=1;
}
}
}
// Kontrolle O
if ( a1=="O" ) {
if ( a2=="O" ) {
if (a3=="O" ) {
G2=1;
A=1;
}
}
}
if ( b1=="O" ) {
if ( b2=="O" ) {
if (b3=="O" ) {
G2=1;
A=1;
}
}
}
if ( c1=="O" ) {
if ( c2=="O" ) {
if (c3=="O" ) {
G2=1;
A=1;
}
}
}
if ( a1=="O" ) {
if ( b1=="O" ) {
if (c1=="O" ) {
G2=1;
A=1;
}
}
}
if ( a2=="O" ) {
if ( b2=="O" ) {
if (c2=="O" ) {
G2=1;
A=1;
}
}
}
if ( a3=="O" ) {
if ( b3=="O" ) {
if (c3=="O" ) {
G2=1;
A=1;
}
}
}
if ( a1=="O" ) {
if ( b2=="O" ) {
if (c3=="O" ) {
G2=1;
A=1;
}
}
}
if ( a3=="O" ) {
if ( b2=="O" ) {
if (c1=="O" ) {
G2=1;
A=1;
}
}
}
//Kontrolle Unentschieden
if ( a1!=" " ) {
if ( a2!=" " ) {
if ( a3!=" " ) {
if ( b1!=" " ) {
if ( b2!=" " ) {
if ( b3!=" " ) {
if ( c1!=" " ) {
if ( c2!=" " ) {
if ( c3!=" " ) {
A=1;
}
}
}
}
}
}
}
}
}
} while ( A!=1 );
// Gewinnbedingung - Unentschieden
if ( G1==1 ) {
System.out.println("*************************************");
System.out.println("***** K R E U Z G E W I N N T *****");
System.out.println("*************************************");
System.out.println("* -...- *");
System.out.println("*************************************");
}
if ( G2==1 ) {
System.out.println("*************************************");
System.out.println("**** K R E I S G E W I N N T ****");
System.out.println("*************************************");
System.out.println("* -...- *");
System.out.println("*************************************");
}
if ( G1!=1 ) {
if ( G2!=1 ) {
System.out.println("***********************************");
System.out.println("*****U N E N T S C H I E D E N*****");
System.out.println("***********************************");
System.out.println("* -by ...- *");
System.out.println("***********************************");
}
}
}
}