From 003119fc27d64e0c94a15190cb093a64fb9887f0 Mon Sep 17 00:00:00 2001 From: kfkama Date: Wed, 16 Feb 2022 15:31:22 +0100 Subject: [PATCH 1/5] Changed Colors to cross and circle --- src/main/java/TicTacToe/Cell.java | 33 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/TicTacToe/Cell.java b/src/main/java/TicTacToe/Cell.java index 2c53223..a254735 100644 --- a/src/main/java/TicTacToe/Cell.java +++ b/src/main/java/TicTacToe/Cell.java @@ -1,6 +1,8 @@ package TicTacToe; import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -13,7 +15,7 @@ public class Cell extends JButton { public Cell(TicTacToeGame _ttt) { ttt = _ttt; - setBackground(new Color(255,255,255)); + setBackground(new Color(255, 255, 255)); addActionListener(new ActionListener() { @Override @@ -28,22 +30,31 @@ public class Cell extends JButton { playerID = ttt.playerID; ttt.endTurn(); setEnabled(false); + repaint(); + } + } - switch (playerID) { - case 1: - setBackground(new Color(255, 0, 0)); - break; - case 2: - setBackground(new Color(0, 0, 255)); - break; - } + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D) g; + + switch (playerID) { + case 1: + g2.drawOval(5, 5, 90, 90); + break; + case 2: + g2.drawLine(5, 5, 90, 90); + g2.drawLine(90, 5, 5, 90); + break; } } - + + protected void reset() { playerID = 0; setEnabled(true); - setBackground(new Color(255,255,255)); + repaint(); } } From 3efe0a8d3eb440f62259509427a14d646f9850cd Mon Sep 17 00:00:00 2001 From: kfkama Date: Wed, 16 Feb 2022 15:33:48 +0100 Subject: [PATCH 2/5] Bugfix unclickable cell --- src/main/java/TicTacToe/Cell.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/TicTacToe/Cell.java b/src/main/java/TicTacToe/Cell.java index a254735..01fd7ab 100644 --- a/src/main/java/TicTacToe/Cell.java +++ b/src/main/java/TicTacToe/Cell.java @@ -28,8 +28,8 @@ public class Cell extends JButton { protected void OnMouseClick() { if (playerID == 0) { playerID = ttt.playerID; - ttt.endTurn(); setEnabled(false); + ttt.endTurn(); repaint(); } } From 3ca691f2a24ba0b81b4645eaf7498e495050f0d6 Mon Sep 17 00:00:00 2001 From: kfkama Date: Wed, 16 Feb 2022 15:35:29 +0100 Subject: [PATCH 3/5] Bugfix turn 8 draw --- src/main/java/TicTacToe/TicTacToeGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/TicTacToe/TicTacToeGame.java b/src/main/java/TicTacToe/TicTacToeGame.java index 7b8fb5a..56f9dc9 100644 --- a/src/main/java/TicTacToe/TicTacToeGame.java +++ b/src/main/java/TicTacToe/TicTacToeGame.java @@ -88,7 +88,7 @@ public class TicTacToeGame extends JPanel { } turns++; - if(turns >= playFieldSize) { + if(turns > playFieldSize) { JOptionPane.showMessageDialog(getParent(),"Draw!"); scoreboard.addPoint(0); resetGame(); From 899ba9bbc4087b344b6204f1c400ff9b57ebb5c5 Mon Sep 17 00:00:00 2001 From: kfkama Date: Wed, 16 Feb 2022 15:46:55 +0100 Subject: [PATCH 4/5] Requested change to darker colors --- src/main/java/TicTacToe/Cell.java | 4 ++-- src/main/java/TicTacToe/Scoreboard.java | 3 +++ src/main/java/TicTacToe/TicTacToeGame.java | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/TicTacToe/Cell.java b/src/main/java/TicTacToe/Cell.java index 01fd7ab..81b8a0f 100644 --- a/src/main/java/TicTacToe/Cell.java +++ b/src/main/java/TicTacToe/Cell.java @@ -15,7 +15,7 @@ public class Cell extends JButton { public Cell(TicTacToeGame _ttt) { ttt = _ttt; - setBackground(new Color(255, 255, 255)); + setBackground(new Color(0)); addActionListener(new ActionListener() { @Override @@ -38,7 +38,7 @@ public class Cell extends JButton { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; - + g2.setPaint(Color.white); switch (playerID) { case 1: g2.drawOval(5, 5, 90, 90); diff --git a/src/main/java/TicTacToe/Scoreboard.java b/src/main/java/TicTacToe/Scoreboard.java index a903129..cbca4a2 100644 --- a/src/main/java/TicTacToe/Scoreboard.java +++ b/src/main/java/TicTacToe/Scoreboard.java @@ -1,5 +1,7 @@ package TicTacToe; +import java.awt.Color; + import javax.swing.JLabel; public class Scoreboard extends JLabel{ @@ -10,6 +12,7 @@ public class Scoreboard extends JLabel{ public Scoreboard(int _playerCount) { playerPoints = new int[_playerCount]; + setForeground(Color.white); updateScores(); } diff --git a/src/main/java/TicTacToe/TicTacToeGame.java b/src/main/java/TicTacToe/TicTacToeGame.java index 56f9dc9..92338f1 100644 --- a/src/main/java/TicTacToe/TicTacToeGame.java +++ b/src/main/java/TicTacToe/TicTacToeGame.java @@ -1,5 +1,6 @@ package TicTacToe; +import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Line2D; @@ -23,6 +24,7 @@ public class TicTacToeGame extends JPanel { public TicTacToeGame() { this.setSize(width, height); + setBackground(Color.black); setLayout(null); initField(); initScoreboard(); @@ -68,6 +70,7 @@ public class TicTacToeGame extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; + g2.setColor(Color.white); Line2D lin = new Line2D.Float(250, 150, 250, 450); Line2D lin2 = new Line2D.Float(350, 150, 350, 450); From 848a5ba499d335d70de776f8626c65a10942e230 Mon Sep 17 00:00:00 2001 From: kfkama Date: Wed, 16 Feb 2022 15:51:57 +0100 Subject: [PATCH 5/5] Bugfix draw order --- src/main/java/TicTacToe/Cell.java | 6 +++--- src/main/java/TicTacToe/TicTacToeGame.java | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/TicTacToe/Cell.java b/src/main/java/TicTacToe/Cell.java index 81b8a0f..b6c4e6b 100644 --- a/src/main/java/TicTacToe/Cell.java +++ b/src/main/java/TicTacToe/Cell.java @@ -41,12 +41,12 @@ public class Cell extends JButton { g2.setPaint(Color.white); switch (playerID) { case 1: - g2.drawOval(5, 5, 90, 90); - break; - case 2: g2.drawLine(5, 5, 90, 90); g2.drawLine(90, 5, 5, 90); break; + case 2: + g2.drawOval(5, 5, 90, 90); + break; } } diff --git a/src/main/java/TicTacToe/TicTacToeGame.java b/src/main/java/TicTacToe/TicTacToeGame.java index 92338f1..642f6e5 100644 --- a/src/main/java/TicTacToe/TicTacToeGame.java +++ b/src/main/java/TicTacToe/TicTacToeGame.java @@ -88,19 +88,21 @@ public class TicTacToeGame extends JPanel { JOptionPane.showMessageDialog(getParent(),"Player: " + playerID + " Wins!"); scoreboard.addPoint(playerID); resetGame(); + } else { + turns++; + if(turns >= playFieldSize) { + JOptionPane.showMessageDialog(getParent(),"Draw!"); + scoreboard.addPoint(0); + resetGame(); + } + + playerID++; + if(playerID >= maxPlayers) { + playerID = 1; + } } - turns++; - if(turns > playFieldSize) { - JOptionPane.showMessageDialog(getParent(),"Draw!"); - scoreboard.addPoint(0); - resetGame(); - } - playerID++; - if(playerID >= maxPlayers) { - playerID = 1; - } } public int checkPlayfield() {