This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
    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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Connect Four Game

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello all,

Our assignment is to make a version of the classic 'Connect Four' game, where we need to construct a GUI that shows the current state of the game and instead of having a winner once a player has four chips in a row, the game needs to continue until no chips can be placed anymore.

We currently get stuck in the GUI part. Running it right now results in a board with empty spaces only. Also after choosing a column to place, the board remains empty.

Our question: How do we get the board filled with the right color of chips at the right place?

We know the 'ArcsPanel'-class (almost at the bottom of the code) is wrong, but we don't know what to do to make it right.

Main class 'ConnectPanel':


Class 'Chip':


Class 'Player':


Thank you for your time!

P.S.: At the moment, only the colors white, red and blue are used. This is purely for finding out how to work in general.
 
Sheriff
Posts: 16917
283
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:
  • Report post to moderator

Lennart van Ham wrote:


1st: Why all static?

2nd: Why is there so much code in main()?

3rd: Are you not being taught how to test your code with JUnit or some other automated unit testing framework?

Separating the UI (the presentation) from the main logic of the game (the model) is one thing you can do to manage the complexity of the program.

Another is to focus on getting the main success scenarios working first. Assume well-behaved users and good input first, add error checking later. Get the main logic working before you add things like "enter your choice in lower case" or "the desired amount of columns is not compatible with this game."

Another is to try to write methods that do one small part. Methods that do too much are complicated and hard to maintain and change. Try to limit methods to 10-15 lines of code max. The fewer lines of code, the better and more focused the method is. That's a good thing.

As it is right now, the code you posted is a bit of a mess. Anyone coming into this code with fresh eyes will need some time to decipher it and follow the "story" that it's trying to tell and maybe a bit more time to find the problem. It would help you and your mates and others who would help if you tried to clean it up a bit. Otherwise, you may have to whittle it down to the part where you think you have a problem before you will get other people to spend time to help look. Or you could get lucky and get the help of someone who's willing to go that extra mile for their fellow rancher
 
Junilu Lacar
Sheriff
Posts: 16917
283
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:
  • Report post to moderator
Just so you know, you have code that fits a known coding anti-pattern - coding horror: arrow code
 
Marshal
Posts: 75637
354
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Junilu Lacar wrote: . . . the code you posted is a bit of a mess.. . .

It might look a bit better if I get rid of some of the long lines for you. Then you can see how it is done.

But you may end up deleting the whole of that code and starting again. I suggest you need some classes. A board class and a disc class might be a good start.
 
Lennart van Ham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thank you all for your replies. Of course we understand this is difficult to decipher for one that is not in on the assignment. Excuse us for this. I will open a new question on 'Beginning Java', named 'Connect Four game', to prevent this one from becoming a complete mess.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Lennart van Ham wrote:Thank you all for your replies.


This thread is now locked. Discussion continues here.

Winston
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
    Bookmark Topic Watch Topic
  • New Topic