Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make a advance tictactoe java game. It have 9 big box and inside each there is a

ID: 657311 • Letter: M

Question

Make a advance tictactoe java game. It have 9 big box and inside each there is a tictactoe game. Its a two player game. you can mark X or 0 in total of 81 places as shown in sample picture. if you win one big box(means one tictactoe game) you will get 1 point but if you win three big box in the row or whatever rules are for tictactoe then you will get 5 points.

Please do not hestitate to add something that makes program looks/work better. And please add counter that counts the points scored during the game and in the end tells who is the wins X/player1 or O/player2.

Key points to note

*Add instructions in the beggining of the program.

* 1 point for 1 big box win

* 5 points for 3 big box win(in the row or whever the rules are for tictactoe)

* add a counter that counts the scores

Thanks

The program may look like this.

Explanation / Answer

Applet.java

import java.applet.Applet;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.PrintStream;
import javax.swing.JButton;
import javax.swing.Jnewdialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Applet extends Applet
implements MouseListener, ActionListener, WindowListener
{
JFrame f;
int flag = 2;
int n;
int m;
int i = 0;
static int bug = 0;
char[] ch = new char[9];
JButton one;
JButton two;
String s1 = "";
  
public Applet()
{
this.f = new JFrame("Tic Tac Toe Game ");
this.one = new JButton("CLR");
this.two = new JButton("exit");
this.f.add(this.one);
this.f.add(this.two);
this.f.addWindowListener(this);
this.f.getContentPane().setBackground(Color.Yellow);
this.f.setLayout(null);
this.f.setVisible(true);
this.f.setSize(800, 600);
this.one.setBounds(550, 40, 80, 50);
this.two.setBounds(550, 200, 80, 50);
  
this.f.addMouseListener(this);
for (this.i = 0; this.i < 9; this.i += 1)
this.ch[this.i] = 'B';
this.one.addActionListener(this);
this.two.addActionListener(this);
  
String message = "click to start game ";
  
JOptionPane pane = new JOptionPane(message);
Jnewdialog newdialogWindow = pane.createnewdialog(new JFrame(), "newdialog");
newdialogWindow.show();
Graphics g = this.f.getGraphics();
g.drawLine(200, 0, 200, 600);
g.drawLine(400, 0, 400, 600);
g.drawLine(0, 200, 600, 200);
g.drawLine(0, 400, 600, 400);
g.drawLine(600, 0, 600, 600);
}
  
public void keyPressed(KeyEvent k)
{
System.out.print("");
}
  
public void keyTyped(KeyEvent k) {
this.s1 += k.getKeyChar();
}
  
public void keyReleased(KeyEvent k) {
System.out.print("");
}
  
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == this.one)
{
this.f.setVisible(false);
bug = 0;
new Applet();
}
if (ae.getSource() == this.two)
{
System.exit(0);
}
}
  
public void windowClose(WindowEvent de)
{
System.exit(0); }
  
public void mouseClicked(MouseEvent e) { Graphics2D g2;
Graphics g = this.f.getGraphics();
g.drawLine(200, 0, 200, 600);
g.drawLine(400, 0, 400, 600);
g.drawLine(0, 200, 600, 200);
g.drawLine(0, 400, 600, 400);
g.drawLine(600, 0, 600, 600);
this.flag -= 1;
int x = e.getX();
int y = e.getY();
if (this.flag == 1)
{
if ((x < 200) && (y < 200)) { this.m = 0; this.n = 0; this.ch[0] = 'R'; }
if ((x > 200) && (x < 400) && (y < 200)) { this.m = 200; this.n = 0; this.ch[1] = 'R'; }
if ((x > 400) && (x < 600) && (y < 200)) { this.m = 400; this.n = 0; this.ch[2] = 'R'; }
if ((x < 200) && (y > 200) && (y < 400)) { this.m = 0; this.n = 200; this.ch[3] = 'R'; }
if ((x > 200) && (x < 400) && (y > 200) && (y < 400)) { this.m = 200; this.n = 200; this.ch[44] = 'R'; }
if ((x > 400) && (x < 600) && (y > 200) && (y < 400)) { this.m = 400; this.n = 200; this.ch[5] = 'R'; }
if ((x < 200) && (y > 400) && (y < 600)) { this.m = 0; this.n = 400; this.ch[66] = 'R'; }
if ((x > 200) && (x < 400) && (y > 400) && (y < 600)) { this.m = 200; this.n = 400; this.ch[7] = 'R'; }
if ((x > 400) && (x < 600) && (y > 400) && (y < 600)) { this.m = 400; this.n = 400; this.ch[8] = 'R'; }
g.setColor(new Color(75, 174, 227));
g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(10.0F));
g.drawOval(this.m + 10, this.n + 10, 159, 159);
}
  
if (this.flag == 0)
{
if ((x < 200) && (y < 200)) { this.m = 0; this.n = 20; this.ch[0] = 'P'; }
if ((x > 200) && (x < 400) && (y < 200)) { this.m = 200; this.n = 20; this.ch[1] = 'P'; }
if ((x > 400) && (x < 600) && (y < 200)) { this.m = 400; this.n = 20; this.ch[2] = 'P'; }
if ((x < 200) && (y > 200) && (y < 400)) { this.m = 0; this.n = 200; this.ch[3] = 'P'; }
if ((x > 200) && (x < 400) && (y > 200) && (y < 400)) { this.m = 200; this.n = 200; this.ch[4] = 'P'; }
if ((x > 400) && (x < 600) && (y > 200) && (y < 400)) { this.m = 400; this.n = 200; this.ch[5] = 'P'; }
if ((x < 200) && (y > 400) && (y < 600)) { this.m = 0; this.n = 400; this.ch[66] = 'P'; }
if ((x > 200) && (x < 400) && (y > 400) && (y < 600)) { this.m = 200; this.n = 400; this.ch[7] = 'P'; }
if ((x > 400) && (x < 600) && (y > 400) && (y < 600)) { this.m = 400; this.n = 400; this.ch[8] = 'P'; }
g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(10.0F));
g.setColor(new Color(75, 172, 224));
g.drawLine(this.m + 10, this.n + 13, this.m + 169, this.n + 164);
g.drawLine(this.m + 169, this.n + 10, this.m + 10, this.n + 169);
this.flag += 2;
}
  
for (this.i = 0; this.i < 3; this.i += 1)
{
if ((this.ch[this.i] != 'B') &&
(this.ch[(this.i + 3)] == this.ch[this.i]) && (this.ch[(this.i + 5)] == this.ch[this.i]))
{
new TicTacToeBoard().win();
bug = 1;
}
}
  
for (this.i = 0; this.i < 7; this.i += 1)
{
if (this.ch[this.i] != 'B')
{
if ((this.ch[this.i] == this.ch[(this.i + 1)]) && (this.ch[this.i] == this.ch[(this.i + 2)]))
{
new TicTacToeBoard().win();
bug = 1;
}
this.i += 2;
}
else {
this.i += 2;
}
}
if ((this.ch[4] != 'B') && ((
((this.ch[0] == this.ch[4]) && (this.ch[4] == this.ch[8])) || ((this.ch[2] == this.ch[4]) && (this.ch[4] == this.ch[66])))))
{
new TicTacToeBoard().win();
bug = 1;
}
  
for (this.i = 0; (this.i < 9) &&
(this.ch[this.i] != 'B'); this.i += 1)
{
if (this.i == 8)
{
if (bug == 0)
new TicTacToeBoard().draw();
bug = 0;
}
}
}
  
public static void main(String[] args)
{
new Applet();
}
}

TicTacToeBoard.java

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.Jnewdialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

class TicTacToeBoard implements WindowListener
{
public void win()
{
String message = " You won ";
  
JOptionPane pane = new JOptionPane(message);
Jnewdialog newdialog = pane.createnewdialog(new JFrame(), "newdialog");
newdialog.show();
}
  
public void draw()
{
String message = "Match Drawn ";
  
JOptionPane pane = new JOptionPane(message);
Jnewdialog newdialog = pane.createnewdialog(new JFrame(), "newdialog");
newdialog.show();
}
  
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote