Tic Tac toe
Author |
Message |
sh4dow
|
Posted: Sun May 24, 2009 2:31 pm Post subject: Tic Tac toe |
|
|
hey guys, I am making a tic tac toe and so far its 2d and i want to make it 3d, how do I add 2 more boxes in order to make it 3d? Any help would be appreciated.  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Dusk Eagle

|
Posted: Sun May 24, 2009 4:04 pm Post subject: Re: Tic Tac toe |
|
|
How do you expect us to help you if you don't post your code ? Remember to use syntax tags!
code: |
[syntax="java"]
//code here
[/syntax]
|
|
|
|
|
|
 |
sh4dow
|
Posted: Sun May 31, 2009 11:13 am Post subject: Re: Tic Tac toe |
|
|
Hey guys, I want to add another panel inside the panel, so that I have 4 tic tac toe's on one screen, making it 3d. How do I add more panels?
Java: |
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TicTacToe implements ActionListener
{
//Class constants
private static int WIDTH = 600;
private static int HEIGHT = 600;
//Design
private static final GridLayout LAYOUT = new GridLayout(3, 3);
// variables
public JFrame Frame = new JFrame("Ultimate Tic Tac Toe");
JButton btn = new JButton("");
JButton btn2 = new JButton("");
JButton btn3 = new JButton("");
JButton btn4 = new JButton("");
JButton btn5 = new JButton("");
JButton btn6 = new JButton("");
JButton btn7 = new JButton("");
JButton btn8 = new JButton("");
JButton btn9 = new JButton("");
String mark = "X";
boolean win = false;
//Constructor
public TicTacToe ()
{
Frame. setSize(WIDTH,HEIGHT );
Frame. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
//Add to the window
Frame. getContentPane(). setLayout(LAYOUT_STYLE );
Frame. getContentPane(). add(btn );
Frame. getContentPane(). add(btn2 );
Frame. getContentPane(). add(btn3 );
Frame. getContentPane(). add(btn4 );
Frame. getContentPane(). add(btn5 );
Frame. getContentPane(). add(btn6 );
Frame. getContentPane(). add(btn7 );
Frame. getContentPane(). add(btn8 );
Frame. getContentPane(). add(btn9 );
//Adds listener
btn. addActionListener(this);
btn2. addActionListener(this);
btn3. addActionListener(this);
btn4. addActionListener(this);
btn5. addActionListener(this);
btn6. addActionListener(this);
btn7. addActionListener(this);
btn8. addActionListener(this);
btn9. addActionListener(this);
Frame. setVisible(true);
}
//ActionPerformed
public void actionPerformed (ActionEvent e )
{
int count= 1;
do
{
if (e. getSource()==btn )
{
btn. setText(mark );
btn. setEnabled(false);
}
else if (e. getSource()==btn2 )
{
btn2. setText(mark );
btn2. setEnabled(false);
}
else if (e. getSource()==btn3 )
{
btn3. setText(mark );
btn3. setEnabled(false);
}
else if (e. getSource()==btn4 )
{
btn4. setText(mark );
btn4. setEnabled(false);
}
else if (e. getSource()==btn5 )
{
btn5. setText(mark );
btn5. setEnabled(false);
}
else if (e. getSource()==btn6 )
{
btn6. setText(mark );
btn6. setEnabled(false);
}
else if (e. getSource()==btn7 )
{
btn7. setText(mark );
btn7. setEnabled(false);
}
else if (e. getSource()==btn8 )
{
btn8. setText(mark );
btn8. setEnabled(false);
}
else if (e. getSource()==btn9 )
{
btn9. setText(mark );
btn9. setEnabled(false);
}
//Press check
if (btn. getText(). equals(btn2. getText()) && btn2. getText(). equals(btn3. getText()) && btn. getText(). equals("")== false)
{
win= true;
}
else if (btn4. getText(). equals(btn5. getText()) && btn5. getText(). equals(btn6. getText())&& btn4. getText(). equals("")== false)
{
win= true;
}
else if (btn7. getText(). equals(btn8. getText()) && btn8. getText(). equals(btn9. getText())&& btn7. getText(). equals("")== false)
{
win= true;
}
else if (btn. getText(). equals(btn4. getText()) && btn4. getText(). equals(btn7. getText())&& btn. getText(). equals("")== false)
{
win= true;
}
else if (btn2. getText(). equals(btn5. getText()) && btn5. getText(). equals(btn8. getText())&& btn2. getText(). equals("")== false)
{
win= true;
}
else if (btn3. getText(). equals(btn6. getText()) && btn6. getText(). equals(btn9. getText())&& btn3. getText(). equals("")== false)
{
win= true;
}
else if (btn. getText(). equals(btn5. getText()) && btn5. getText(). equals(btn9. getText())&& btn. getText(). equals("")== false)
{
win= true;
}
else if (btn3. getText(). equals(btn5. getText()) && btn5. getText(). equals(btn7. getText())&& btn3. getText(). equals("")== false)
{
win= true;
}
else if (count== 9 && win== false)
{
}
System. out. println(count );
if (count!= 9 && win== true)
{
JOptionPane. showMessageDialog(null, mark + " WINS!");
System. exit(1);
}
if (mark. equals("X"))
{
mark= "O";
}
else
{
mark= "X";
}
}
while(win= false);
}
public static void main (String[] args )
{
TicTacToe gui = new TicTacToe (); //summons it the window to the screen
}
}
|
|
|
|
|
|
 |
|
|