Question: I need to implement game logic for tic tac toe in this code. Can someone help me. It just needs to be a a player

 I need to implement game logic for tic tac toe in this code. Can someone help me. It just needs to be a a player vs player again and ask if you want to play again. import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class TicTacToe { public static void main(String[] args) { JFrame frame = new JFrame(" TicTacToe"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(290, 300); Board board = new Board(); frame.add(board); frame.setResizable(false); frame.setVisible(true); } } class Board extends JComponent { private int w = 265, h = 265; char player = 'X'; public Board(){ addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { int x = me.getX(); int y = me.getY(); int sideWidth = w / 3; int sideHeight = h / 3; int a = x / sideWidth; int b = y / sideHeight; int xStart = sideWidth * a + 10; int yStart = sideHeight * b + + sideHeight - 10; Graphics g = getGraphics(); g.setFont(new Font("monospaced", Font.PLAIN, 110)); g.drawString(player + "", xStart, yStart); if (player == 'X') { player = 'O'; } else { player = 'X'; } if } }); } public void paint(Graphics g) { g.drawLine(90, 0, 90, 300); g.drawLine(185, 0, 185, 300); g.drawLine(0, 85, 300, 85); g.drawLine(0, 175, 300, 175); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!