• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

GUI for the Tic Tac Toe game

 
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Looking for a little help with my next project. The overview of this project is to develop a GUI front-end  for the Tic Tac Toe game I created in earlier programs. I worked though the code and was able to compile the program. But I notice it's not looking the way it should. Your feedback would be greatly appreciated.



cell.java



Board.java



Mark.java



Player.java

 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I missed one more java file.

Outcome.java

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to pass parameters (3,3) here


}
 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I totally overlooked that! Thanks, It's good to have  a second pair of eyes.
 
Vasyl Lyashkevych
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a nice time!
 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again, Trying to wrap up this project  but keep hitting walls. I am able to display and even place X's and O's on the game board, now I am applying the logic to handle each turn and determine the outcome of the game.
I have put in the code but when I compile it, I doesn't  give me an error but I don't get any interaction through the game as well. I believe it's the for(Outcome) { statement, but I'm unsure what to replace it with?


 
Bartender
Posts: 5562
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thre are some problems with this last code.

1) in class Board, line 12, use:

2) in class TicTacToeGUIGame, line 45, this doesn't compile:

3) method getOutcome(): this doesn't make sense:

4) in line 47, this doesn't compile:
.
Can you have a look at these?
 
Sheriff
Posts: 17696
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OP: The code you posted has a wide range of problems in it. I'll focus on the high-level problem.

The code/design lacks separation of concerns. The GUI logic is tightly bound to the game/domain logic, otherwise known as the "business" logic. That causes all sorts of problems, not the least of which is excessive complexity. Your statements "keep hitting walls... I don't get any interaction... it's the for(Outcome)" are symptoms of overly complex code and code that hasn't been separated across concerns. Imagine if your body had its digestive functions and respiratory functions mixed together in one organ. You'd probably have trouble figuring out if you were having indigestion or asthma.

The Outcome enum also leads you to more procedural instead of object-oriented code/design. The code in the getOutcome() method is definitely procedural code, not object-oriented.

Unless these issues are address, you will continue to hit walls. You might be able to crawl over those walls but your code will bear the marks of the pain you had to go through in finding workaround after workaround and it won't be pretty.

Explaining the things you can do to fix the design properly is going to take more than just a few bullet points though, so I'll post those separately if you're interested in knowing what they are. Be forewarned though, the fixes I will suggest involve throwing away a lot of the code you've written.
 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response. You are correct, this codes complexity will only continue to cause me problems. I will take your advice and scrap it and try again. Thanks again!
 
Junilu Lacar
Sheriff
Posts: 17696
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before you scrap it and try again, make sure you understand the problem, why it's a problem, and what the alternative is.

Separating concerns is not easy, even for those experienced at thinking along those lines. Our brains tend to be greedy and tend to want to get as much of a task done at one go. Also, the untrained brain cannot easily recognize where the separation needs to happen. Yes, the boundary between GUI vs Domain logic seems to be pretty clear cut but the devil is in the details.

My advice is to step through the process of turning this poorly constructed design into a progressively better one. It's a process called refactoring and one you would benefit from learning early on. If you want to get good at programming, you'll have to get used to and be really good at refactoring. Nobody writes perfect code the first, second, third, even fourth time around. Nobody. Not even the best of the best. Well, not all of the time at least. We'll always make a mistake here or there. Beginners will make more mistakes than experts make, obviously. Ironically, it's the beginners who don't refactor as often enough. Most beginners don't refactor at all.

Don't throw away and start over. Refactor and replace with better. The bad is what gets thrown away.
 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again, Thanks for all your feedback it has help me get through some of the confusing times I've had with Java code. I reworked the previous code I sent and thought I had it completed. I'm not receiving any errors, but the program is still not allowing me to determine whether Nought wins, Cross wins, or there's a tie. I am reusing a code I used in earlier programs and was able to get it working there, but for some reason can't seam to get it working on this program. Can anyone help?



I only made changes to the tictactoeguigame.java. all the only classes where untouched. Thanks again.
 
Marshal
Posts: 79967
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I am late to the party, but there is something very wrong with your GUI trying to work out the logic of the game. You said you were adding a GUI to an existing game, which is correct, so why have you get lines 44‑64 at all? Your GUI shou‍ld do things like passing on messages to the game like, “X clicked square 4”. The game will then work out whether that is a valid move, whether the game is won or lost, and update the GUI/display.
Your logic for calculating who won is far too complicated; it can be simplified no end. You can also enhance the game to use a 4×4 board or an n×n board, but your current logic would make such an enhancement very difficult.
 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes! I was instructed to make my oop version of the tic tac toe game and turn it into a GUI version. The only problem I'm having is I can't get the game to play through and determine whether Nought wins or Cross wins or there is a tie?
 
Junilu Lacar
Sheriff
Posts: 17696
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your OOP version work? If it does and if it was properly structured, adapting that program to work with a GUI should not break it.  Imagine replacing the monitor that you're using with your desktop computer and that resulting in your computer not working anymore. That doesn't make sense, right? Neither does it make sense when you say that you made a working OOP version TicTacToe program but broke it when added a GUI. That tells me that your OOP version probably wasn't very OOP after all. Perhaps you should share the code you have for the OOP version that worked. Then we can compare it with the OOP+GUI version of the code that doesn't work.
 
Lee High
Greenhorn
Posts: 22
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my oop version of the game.

 
Junilu Lacar
Sheriff
Posts: 17696
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When all your methods are static, it's not really an OOP program. It's procedural code that's cloaked in the trappings of a class. Sorry, but that's not OOP.
 
Campbell Ritchie
Marshal
Posts: 79967
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another problem is that you are putting everything in the one class; you shou‍ld have a Player class, Symbol, Board, or similar.
Also, please indent your code correctly; you cannot see where methods start and finish.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic