From 98c94cee62a43b0311cc1292a78e7b799d2a8e7c Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 7 Oct 2021 15:45:35 +0200 Subject: [PATCH] Class Gamefield implemented --- src/Gamefield.java | 110 +++++++++++++++++++++++++++++++++++++++++++++ src/TicTacToe.java | 17 +++++-- 2 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/Gamefield.java diff --git a/src/Gamefield.java b/src/Gamefield.java new file mode 100644 index 0000000..39cced8 --- /dev/null +++ b/src/Gamefield.java @@ -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 " "; + } + } + +} \ No newline at end of file diff --git a/src/TicTacToe.java b/src/TicTacToe.java index 2e52f8a..263920f 100644 --- a/src/TicTacToe.java +++ b/src/TicTacToe.java @@ -1,8 +1,19 @@ public class TicTacToe { public static void main(String[] args) { - System.out.println("Test Andrin"); - System.out.println("Test Leo"); - System.out.println("Test Roman"); //test + System.out.println("test"); + } + + public TicTacToe(String int1, int int2) { + + } + + public int test(int int2, int int1){ + return 3; + } + + public void test2() { + this.test(3, 6); + } }