Jj$*Oh!xOTM7)?6Mt4sut(|5Lc0tQZVs*
de_E%1uu0!+=<^laSbyJo{lgpTpNqVl{}S6otBttL^egXY;4=uQ81=Q3hIjHmByGJi=#Bp
z(mbus70msEp@KCi9<)L$Omlrbd5(2?7sVMXov=uvY#5cPvc{7qrndO)E2YLItO~e2UK9b!w@k=ERn`rz0#(-92Kku6DxEcJr~iz
lYF+Qnp#xqsK%WQ$YrhfiJMjPj
literal 0
HcmV?d00001
diff --git a/FourWins/out/production/VierGewinnt/META-INF/MANIFEST.MF b/FourWins/out/production/VierGewinnt/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5ee19cb
--- /dev/null
+++ b/FourWins/out/production/VierGewinnt/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: Main
+
diff --git a/FourWins/out/production/VierGewinnt/Main.class b/FourWins/out/production/VierGewinnt/Main.class
new file mode 100644
index 0000000000000000000000000000000000000000..6009b89e57213f7c70c4ee19f7a5e4d97af8d8b3
GIT binary patch
literal 385
zcmZutu};G<5Pg@VF$sm17Rt<47|4Rup{PqGrT{}x5n^(J6$SNP6(#elOl9dZPd+b
znJIfGvyz!!TII5wORHV|O9u6`eqoLDT52=q?Ij~&FnmlGaxIfmnj)FiR-0nns7qV$
zeE**|A)Zw$o2x7B>>{Ul?nK%MAqZkxnc7w*o46LCyLGtD7AmiCf`DJ>jt9OJ1jik&
z5=LTdoozs`O*`TkHYEFU-u@ZDE@wc5J?t~%mPd^kbMNpTHt_Ga0`4CHpT~kfA`v?1
LGEX?*=%M!wPPIdT
literal 0
HcmV?d00001
diff --git a/FourWins/src/Canvas.java b/FourWins/src/Canvas.java
new file mode 100644
index 0000000..bfb441c
--- /dev/null
+++ b/FourWins/src/Canvas.java
@@ -0,0 +1,108 @@
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+public class Canvas extends JPanel
+{
+ private int sizeX;
+ private int sizeY;
+ private Graphics2D g2d;
+ private Control control;
+ private Color[][] grid;
+ private GUI gui;
+
+ private Line winLine;
+
+ public Canvas(Control control, Color[][] grid, GUI gui)
+ {
+ this.grid = grid;
+ this.control = control;
+ this.gui = gui;
+
+ winLine = control.getWinLine();
+
+ addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mouseClicked(MouseEvent e)
+ {
+
+ if (e.getButton() == 1)
+ {
+ int x = e.getX() / sizeX;
+ control.placeCoin(x, true);
+ }
+ }
+ });
+ }
+
+
+ @Override
+ public void paintComponent(Graphics g)
+ {
+ sizeX = gui.getWidth() / Control.fieldsCountX;
+ sizeY = gui.getHeight() / Control.fieldsCountY;
+
+ super.paintComponent(g);
+ g2d = (Graphics2D) g;
+
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+ g2d.setStroke(new BasicStroke(2));
+
+ int yHover = -100;
+ int xHover = -100;
+
+ int finalSize = Math.min(sizeX, sizeY);
+
+ if (getMousePosition() != null)
+ {
+ try
+ {
+ xHover = (int) (getMousePosition().getX()) / sizeX;
+ yHover = control.placeCoin(xHover, false);
+ } catch (Exception e)
+ {
+
+ }
+ }
+
+ for (int x = 0; x < Control.fieldsCountX; x++)
+ {
+ for (int y = 0; y < Control.fieldsCountY; y++)
+ {
+ if (grid[x][y] != null)
+ {
+ if (grid[x][y] == Color.RED)
+ {
+ g2d.setColor(java.awt.Color.RED);
+ } else if (grid[x][y] == Color.GREEN)
+ {
+ g2d.setColor(java.awt.Color.GREEN);
+ }
+
+ g2d.fillOval(x * sizeX + 3, y * sizeY + 3, finalSize - 6, finalSize - 6);
+ } else
+ {
+ g2d.setColor(java.awt.Color.GRAY);
+ g2d.drawOval(x * sizeX + 3, y * sizeY + 3, finalSize - 6, finalSize - 6);
+ }
+ }
+ }
+
+
+ if (winLine.x1 != winLine.x2 || winLine.y1 != winLine.y2)
+ {
+ g2d.setColor(java.awt.Color.GRAY);
+ g2d.setStroke(new BasicStroke(5));
+ g2d.drawLine(winLine.x1 * sizeX + sizeX / 2, winLine.y1 * sizeY + sizeY / 2, winLine.x2 * sizeX + sizeX / 2, winLine.y2 * sizeY + sizeY / 2);
+ }
+
+ float transparency = yHover < 0 ? 0 : 0.5f;
+ g2d.setColor(control.getCurrentPlayer() == Color.RED ? new java.awt.Color(1, 0, 0, transparency) : new java.awt.Color(0, 1, 0, transparency));
+ g2d.fillOval(xHover * sizeX - 2, yHover * sizeY - 2, finalSize + 5, finalSize + 5);
+
+ repaint();
+ }
+}
diff --git a/FourWins/src/Color.java b/FourWins/src/Color.java
new file mode 100644
index 0000000..7657b38
--- /dev/null
+++ b/FourWins/src/Color.java
@@ -0,0 +1,3 @@
+public enum Color {
+ RED, GREEN
+}
diff --git a/FourWins/src/Control.java b/FourWins/src/Control.java
new file mode 100644
index 0000000..811e39f
--- /dev/null
+++ b/FourWins/src/Control.java
@@ -0,0 +1,193 @@
+public class Control
+{
+
+ public static int fieldsCountX = 15, fieldsCountY = 10;
+ private Color[][] grid;
+ private Color currentPlayer = Color.RED;
+
+ private GUI gui;
+ private Line winLine = new Line();
+
+ public Control()
+ {
+ gui = new GUI(this);
+
+ boolean success = false;
+
+ while(!success)
+ {
+ String[] size = new String[2];
+
+ try
+ {
+ size = gui.showSettings().split(",");
+ }
+ catch(NullPointerException e)
+ {
+ System.exit(0);
+ }
+
+
+
+ try
+ {
+ fieldsCountX = Integer.parseInt(size[0]);
+ fieldsCountY = Integer.parseInt(size[1]);
+ success = true;
+ } catch (NumberFormatException e)
+ {
+
+ }
+ }
+
+ grid = new Color[fieldsCountX][fieldsCountY];
+ gui.createGameWindow(grid);
+ }
+
+
+ public int placeCoin(int x, boolean realPlace)
+ {
+ if (grid[x][0] == null)
+ {
+ for (int i = 0; i < fieldsCountY; i++)
+ {
+ if (grid[x][i] != null)
+ {
+ if (realPlace)
+ {
+ grid[x][i - 1] = currentPlayer;
+ if (checkWin())
+ {
+ gui.showWinner(currentPlayer);
+ resetGame();
+ }
+ currentPlayer = currentPlayer == Color.RED ? Color.GREEN : Color.RED;
+ }
+ return i - 1;
+ } else if (i == fieldsCountY - 1)
+ {
+ if (realPlace)
+ {
+ grid[x][i] = currentPlayer;
+ if (checkWin())
+ {
+ gui.showWinner(currentPlayer);
+ resetGame();
+ }
+ currentPlayer = currentPlayer == Color.RED ? Color.GREEN : Color.RED;
+ }
+ return i;
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ private void resetGame()
+ {
+ winLine.reset();
+ for(int x = 0; x < fieldsCountX; x++)
+ {
+ for(int y = 0; y < fieldsCountY; y++)
+ {
+ grid[x][y] = null;
+ }
+ }
+ }
+
+ private boolean checkWin()
+ {
+ for (int x = 0; x < fieldsCountX; x++) {
+ for (int y = 0; y < fieldsCountY; y++) {
+ if (grid[x][y] == currentPlayer) {
+ int countHorizontal = 0;
+ int countVertical = 0;
+ int countDiagonal1 = 0;
+ int countDiagonal2 = 0;
+
+ for (int i = 1; i <= 3; i++) {
+ if(x + i < fieldsCountX) {
+ if(grid[x + i][y] == currentPlayer)
+ {
+ countHorizontal++;
+ if(countHorizontal == 3)
+ {
+ winLine.x1 = x;
+ winLine.x2 = x + i;
+ winLine.y1 = winLine.y2 = y;
+ return true;
+ }
+ }
+
+ if(y + i < fieldsCountY) {
+ if(grid[x + i][y + i] == currentPlayer)
+ {
+ countDiagonal1++;
+ if(countDiagonal1 == 3)
+ {
+ winLine.x1 = x;
+ winLine.x2 = x + i;
+ winLine.y1 = y;
+ winLine.y2 = y + i;
+ return true;
+ }
+ }
+ }
+ }
+ if(y + i < fieldsCountY) {
+ if(grid[x][y + i] == currentPlayer)
+ {
+ countVertical++;
+ if(countVertical == 3)
+ {
+ winLine.x1 = winLine.x2 = x;
+ winLine.y1 = y;
+ winLine.y2 = y + i;
+ return true;
+ }
+ }
+
+ if(x - i >= 0) {
+ if(grid[x - i][y + i] == currentPlayer)
+ {
+ countDiagonal2++;
+ if(countDiagonal2 == 3)
+ {
+ winLine.x1 = x;
+ winLine.x2 = x - i;
+ winLine.y1 = y;
+ winLine.y2 = y + i;
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ for(int i = 0; i < fieldsCountX; i++)
+ {
+ if(grid[i][0] == null)
+ {
+ return false;
+ }
+ }
+
+ gui.showWinner(null);
+ resetGame();
+ return false;
+ }
+
+ public Line getWinLine()
+ {
+ return winLine;
+ }
+
+ public Color getCurrentPlayer()
+ {
+ return currentPlayer;
+ }
+}
diff --git a/FourWins/src/GUI.java b/FourWins/src/GUI.java
new file mode 100644
index 0000000..b99ba7b
--- /dev/null
+++ b/FourWins/src/GUI.java
@@ -0,0 +1,54 @@
+import javax.swing.*;
+import java.awt.*;
+
+public class GUI extends JFrame {
+
+ private Canvas canvas;
+ private Control control;
+
+ public GUI(Control control){
+ this.control = control;
+
+ }
+
+ public void createGameWindow(Color[][] grid)
+ {
+ getContentPane().setPreferredSize(new Dimension(Control.fieldsCountX * 50, Control.fieldsCountY * 50));
+ pack();
+
+ setLocationRelativeTo(null);
+ setTitle("Vier gewinnt");
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ setResizable(false);
+
+ canvas = new Canvas(this.control, grid, this);
+
+ add(canvas);
+
+ setVisible(true);
+ }
+
+ public void showWinner(Color color)
+ {
+ String opt = color == Color.RED ? "Rot" : "Gruen";
+ opt = color == null ? "Niemand" : opt;
+
+ JOptionPane.showMessageDialog(new JFrame(), opt + " hat gewonnen");
+ }
+
+ public String showSettings()
+ {
+ return JOptionPane.showInputDialog(new JFrame(), "Wir groß soll das Spiel sein? \n breite,hoehe");
+ }
+
+ public int getWidth()
+ {
+ return getContentPane().getWidth();
+ }
+
+ public int getHeight()
+ {
+ return getContentPane().getHeight();
+ }
+
+}
diff --git a/FourWins/src/Line.java b/FourWins/src/Line.java
new file mode 100644
index 0000000..e12f85d
--- /dev/null
+++ b/FourWins/src/Line.java
@@ -0,0 +1,9 @@
+public class Line
+{
+ public int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
+
+ public void reset()
+ {
+ x1 = x2 = y1 = y2 = 0;
+ }
+}
diff --git a/FourWins/src/META-INF/MANIFEST.MF b/FourWins/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5ee19cb
--- /dev/null
+++ b/FourWins/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: Main
+
diff --git a/FourWins/src/Main.java b/FourWins/src/Main.java
new file mode 100644
index 0000000..e63c63a
--- /dev/null
+++ b/FourWins/src/Main.java
@@ -0,0 +1,5 @@
+public class Main {
+ public static void main(String[] args) {
+ new Control();
+ }
+}