Class Gamefield implemented

This commit is contained in:
schrom01 2021-10-07 15:45:35 +02:00
parent 8c0224bf08
commit 98c94cee62
2 changed files with 124 additions and 3 deletions

110
src/Gamefield.java Normal file
View File

@ -0,0 +1,110 @@
public class Gamefield {
private int field1, field2, field3, field4, field5, field6, field7, field8, field9;
Gamefield() {
field1 = 0;
field2 = 0;
field3 = 0;
field4 = 0;
field5 = 0;
field6 = 0;
field7 = 0;
field8 = 0;
field9 = 0;
}
public void setField(int field, int player) {
if(field == 1) {
field1 = player;
}
else if(field == 2) {
field2 = player;
}
else if(field == 3) {
field3 = player;
}
else if(field == 4) {
field4 = player;
}
else if(field == 5) {
field5 = player;
}
else if(field == 6) {
field6 = player;
}
else if(field == 7) {
field7 = player;
}
else if(field == 8) {
field8 = player;
}
else if(field == 9) {
field9 = player;
}
}
public int getField(int field) {
if(field == 1) {
return field1;
}
else if(field == 2) {
return field2;
}
else if(field == 3) {
return field3;
}
else if(field == 4) {
return field4;
}
else if(field == 5) {
return field5;
}
else if(field == 6) {
return field6;
}
else if(field == 7) {
return field7;
}
else if(field == 8) {
return field8;
}
else if(field == 9) {
return field9;
}
return -1;
}
public void outputField() {
System.out.print(getSymbol(field1));
System.out.print("|");
System.out.print(getSymbol(field2));
System.out.print("|");
System.out.println(getSymbol(field3));
System.out.println("_____");
System.out.print(getSymbol(field4));
System.out.print("|");
System.out.print(getSymbol(field5));
System.out.print("|");
System.out.println(getSymbol(field6));
System.out.println("_____");
System.out.print(getSymbol(field7));
System.out.print("|");
System.out.print(getSymbol(field8));
System.out.print("|");
System.out.println(getSymbol(field9));
}
private String getSymbol(int player) {
if(player == 1) {
return "X";
}
else if(player == 2) {
return "O";
}
else {
return " ";
}
}
}

View File

@ -1,8 +1,19 @@
public class TicTacToe { public class TicTacToe {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Test Andrin"); System.out.println("test");
System.out.println("Test Leo"); }
System.out.println("Test Roman"); //test
public TicTacToe(String int1, int int2) {
}
public int test(int int2, int int1){
return 3;
}
public void test2() {
this.test(3, 6);
} }
} }