• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tic-Tac-Toe Bugs -solved-  RSS feed

 
Mark Quin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make Tic-Tac-Toe except when I try to have more then one square something goes broke. Right now I am trying to get just the Top Left and center left square to work. But when I click it part works once but then it seems to just lock up and no longer lets me make another move.

Any ideas on how I can fix it?

By I think the bug is in this part of my code:

[ November 14, 2007: Message edited by: Mark Quin ]
 
Mark Quin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone, know anything about what is going wrong with my code?
 
Bert Bates
author
Sheriff
Posts: 8954
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm promoting this to the intermediate forum...
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Mark Quin:]   serialVersion because Big Brother is watching
That stuff goes in Meaningless Drivel
[Mark Quin:]   trying to get just the Top Left and center left square to work
Go ahead and allocate something, if you know how, that will be all the squares and just use the top left one or something.

What are ttl, ctl and tcl and so on ?

In one line you assign a numeric to indicate square taken, in another boolean - try to make some consistency and since taken is by nature boolean ... then make the variable boolean.

You do if (event.getY()>= 100 && event.getY()<= 200){ which is correct in that it does or is a placeholder for error checking, but if the whatchamacallit passes the test, then drop directly into making the square's boolean consistent with that test. Also there is no System.out.println() when I tried to prototype my GUI over the last month: You have to do something along the lines of a Dialog Box or have a text field or text area that you put such stuff up in ~ There is probably a status bar class in swing: try Java Code Example: JStatus Bar which is probably not the ideal collection of java advices but his window drawing code looks more conformant than that which you posted.

[Mark Quin:]   Demonstrate class extension and mouse listeners.

Is this homework ? We don't do homework.

private static final long serialVersionUID = 1L;

You have got it wrong anyway and I don't think it is gonna be used much longer anyway and so just don't use it right now unless a Really Big Brother says you have to, it will not affect compiles or testing as you posted it.

private Display it;

Well if it is 'other classes' then it should not be private, make it public and what is it for ?

Your //Set up a window and // add Display are well meaning, and may well display a displayable window but are characteristic of someone who has not spent enough time in the tutorials, just spend more time there -> that is what I have to do.

Look in awt some more for your //Line spaceing, try to use something that sounds like line or something .... just dig around ... lines can be given state with variables like (Point ,Point) Just write or find something that notes the endpoints in terms of x,y | x,y pairs and then declare multiple variables off of the same data-type, look in Applet demos, try to stick with JStuff if your compiler and Applet are conformant == do not mix JStuff with awt unless you really, really cannot find another way.

YOur void mousePressed(MouseEvent event duplicates code seen earlier, something is wrong that would be best analyzed by Object Oriented Camp - there are plenty of them here @ Java Ranch and should speak up for you.

you should do this.getContentPane.add(new Display),also you need to hava a type to the left of   it = new Display();   the type would be display.

A typical varable declaration looks like this:



The second one is called an Object, everyting in Java is either an Object, a primitive or an Array, but an array looks like



There is also an Array class, but it is a class and not an array.

If you are gonna code in computer science, you will see enough of stuff like this last sentence that it will become second self, no big deal.
 
Mark Quin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are ttl, ctl and tcl and so on ?

ctl= Cube and then the abbreviation for the area "top left"
ttl= Space Taken and abbreviation for the area "top left"

System.out.println()
I am using eclipse so it works because I have the console open.

Is this homework ? We don't do homework.

I reused some of my old java projects.

private static final long serialVersionUID = 1L;

At the time I put that in a long time ago I needed it.

arrays

Ya, I know about arrays. I was just trying to get something simple to work before I tried getting all of the squares to work.

Anyways, thank you for you help.

Also, I got the thing to work now:
if (event.getY() <= 100){
if (tTL == false){ //Check if square is taken
if (player == 1){ //Check if player 1
cTL = true;//X takes the square
repaint();
tTL=true;//space taken

}
else {
cTL = false;//O takes the square
repaint();
tTL=true;//space taken
}
tTL=true;//space taken
System.out.println("Top Left");
}

[ November 14, 2007: Message edited by: Mark Quin ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!