Results 1 to 8 of 8

Thread: Java Tic-Tac-Hoe ;)

  1. #1

    Java Tic-Tac-Hoe ;)

    well as a final exam project for my very basic intro to java class, i was given the chance to make a 'well developed project', so i chose to make a very simple tic-tac-toe game... after all was said and done, the game was spewing unnecessary code and had two different levels of AI, but it worked and my teacher gave me the 100% on it =) so ive taken the liberty of posting it up here for anyone who wants to mess with it or play tic tac toe =)

    thanks to chsh for his demoralizing words of help on irc and zerocool for his testing of the game =)

    jag

  2. #2
    [edit]

    the batch file in the zip assumes that ur path is set to what my computer had it, which the default location where the sun installer installs the java sdk, u might have to tweak it if u plan on using that to run it.

  3. #3
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Ok, that isn't a bad program as it stands (although I'm sure chsh would disagree :P), but there are a few things that I think you should do:

    1) Add more comments; I don't know about other people, but I can't be bothered going through lines and lines of constant code

    2) Do you not find it annoying that your program quits when you close the "you have won/lost" screen? The first time I played I was expecting to be able to play again. The solution to this is to not use the EXIT_ON_CLOSE action for the win/lose window. I'll put in a sample solution to this problem at the end.

    3) I think you should separate the win/lose window into a seperate class in a separate file to make your code easier to figure out. I'm not sure what other people's thoughts on this are, but I tend to separate each window into its own file unless there is some good reason for not doing so. What I would do in the case of your win/lose window is create a new class which takes either a boolean variable as an argument to its constructor which indicated whether or not a user had won or lost or a string that let you set the title. The former might suit this program better, but the latter would be more adaptable if you needed something similar in another program.

    If I think of anything else I'll either edit this post or post another reply, and here's the sample code to allow you to close one window without killing the whole program:

    Code:
    myFrame.setDefaultCloseOperation(HIDE_ON_CLOSE);
    or if none of the default close operations do what you want and you want to specify it:

    Code:
    myFrame.addWindowListener(new WindowAdapter()
    {
    	public void windowClosing(WindowEvent e)
    	{
    		dispose(); // or whatever you want it to do
    	}
    }
    Obviously I'm not saying that this is what you must do or anything, but I think it would improve your program. Otherwise, good prog.

    ac

  4. #4
    I agree on all your points... =)

    Response to your points in order:

    1) I originally wanted to comment nicely and explain what every line of code meant, but it became too much of a hassle when I was codiing and trying to get the program to work and then when I finished, I never sat down and did it... sort of put it off from the beginning.

    2) Yea, I found that annoying and originally was going to have the program create a new GUI object and just kill the old one but just like the commenting, it was put off and off until it never happened.

    3) As for separating that disaster I have in my ButtonListener class, I completely agree it should be spilt up into multiple classes but since I spent about 5 minutes planning this program out and not writing out a flow chart or anything, it all become packed into one... sort of bad design on my part. =\...

    Thanks for reviewing the code and for the comments... I might redo this game and clean everything up sooner or later but I've started work on a Java address book so we'll see. =P

    - dave t

  5. #5
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    lol, everyone knows you won't go back and fix the problems, or that if you do you are incredibly dedicated. I always say to myself that I'll maybe go back and do stuff later, but it never happens. I add comments while I'm coding most of the time (or I'll write a section then add comments) because otherwise I just leave them out.

    I enjoyed reviewing your code and also feel that I should do that cause I've posted a few things here and asked for them to be reviewed, so I should also give back to the community.

    ac

  6. #6
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Man, no-one's gonna read this, but the argument to setDefaultCloseOperation(...) should have actually been DISPOSE_ON_CLOSE surprisingly enough.

    ac

  7. #7
    Heh, I'll read it because its my thread.. =)

    But since you've taken the time to find that for me, I guess I'm sort of forced to go back and fix thre program up later this summer. =P

  8. #8
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    lol...man, I'm trying to design a gui for a simple program that I'm making just now and swing just isn't having it. It's basically impossible to get everything looking right because of the way that the infernal thing stretches everything!

    Ah well...I'll get it right tomorrow.

    ac

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •