Bookmark Topic Watch Topic
  • New Topic

Connect Four Game  RSS feed

 
Lennart van Ham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Just so you know, you have code that fits a known coding anti-pattern - coding horror: arrow code
 
Campbell Ritchie
Marshal
Posts: 56597
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Lennart van Ham wrote:Thank you all for your replies.

This thread is now locked. Discussion continues here.

Winston
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!