...

View Full Version : Help with Tic Tac Toe [Jcreator]



pineappelle
03-29-2012, 06:00 PM
The code below is for tic tac toe in Jcreator but I can't get it to swtich turns. What am I doing wrong?


/**
* @(#)tictactoe.java
*
* tictactoe Applet application
*
* @author
* @version 1.00 2012/3/27
*/

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class tictactoe extends java.applet.Applet implements MouseListener, MouseMotionListener {

int x, y;
boolean one, two, three, four, five, six, seven, eight, nine, square, circle, clicked;

public void init() {

addMouseListener(this);
addMouseMotionListener(this);
square=true;

}

public void paint(Graphics screen) {

screen.drawLine(200,0,200,600);
screen.drawLine(400,0,400,600);
screen.drawLine(0,200,600,200);
screen.drawLine(0,400,600,400);

if(one==true) {
if(square==true) {
screen.drawRect(10,10,180,180);
}
if(circle==true) {
screen.drawOval(10,10,180,180);
}
}

if(two==true) {
if(square==true) {
screen.drawRect(210,10,180,180);
}
if(circle==true) {
screen.drawOval(210,10,180,180);
}
}

if(three==true) {
if(square==true) {
screen.drawRect(410,10,180,180);
}
if(circle==true) {
screen.drawOval(410,10,180,180);
}
}

}

public void mouseClicked(MouseEvent event) {

x=event.getX();
y=event.getY();

if(x>0 && x<200 && y>0 && y<200) {
one=true;
repaint();
}
if(x>200 && x<400 && y>0 && y<200) {
two=true;
repaint();
}
if(x>400 && x<600 && y>0 && y<200) {
three=true;
repaint();
}

checkturn();
clicked=true;


}
public void mouseReleased(MouseEvent event) {
}
public void mousePressed(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseExited(MouseEvent event) {
}
public void mouseDragged(MouseEvent event) {
}
public void mouseMoved(MouseEvent event) {
}

public void checkturn() {

if(clicked==true && square==true) {

clicked=false;
square=false;
circle=true;

}
if(clicked==true && circle==true) {

clicked=false;
circle=false;
square=true;

}

}

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum