Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago