During freshmen year of college, I took a project-oriented course in which we were to form teams, choose a project, and practice project design and development throughout the semester. My team, never wanting to play it safe or easy, chose to build four-player chess via Java (yes, this does exist).
Starting out, we wanted to ensure that we could meet some basic requirements.
- Four player and two player functionality
- Written in Java
- Self-designed graphical user interface
- Human vs human and human vs computer functionality
- Know when check-mate occurs
- Advise user of illegal moves
Out of our group of three, only one of us had had previous Java knowledge while the rest of us were learning it as we went along. It was rough, but by taking the plunge, we were able to really test ourselves.
Our project can be divided into # main components:
- Board logic
- Piece management
- Player input/interaction
The board class was the meat of the project, in that it kept track of the pieces, checked to see whether the any of the four kings were in check, what the available move set was for the selected piece, and whether the piece was allowed to make a valid move. It also handled player turns, player removal upon check mate, and any other high-level tasks.
The movement of the pieces themselves was handled by a combination of the jSwing library and the board class, however we also implemented a special highlighted and piece class to aid in the representation of individual pieces. The highlighted class allowed us to overlay either yellow or red boarders on the squares of the board to indicate possible moves, while the piece class allowed us to draw each piece’s graphic.
We did end up using the jSwing library to handle most of our user interface tasks. We created a window to hold the game itself along with a few menus to allow customization, and used mouse listeners to capture and act upon mouse click events.
Lastly, we created all of our graphics ourselves, based upon a couple of different chess-set designs. We mostly used MSpaint for this, trying to keep file size down to the bare-minimum. We were not, unfortunately, particularly efficient when drawing items to the screen, but for a first attempt at a graphical UI, we were relatively pleased.
As a result, we were successful in almost all of our initial requirements. We were able to create a fully functional and operational GUI for the user to use. We were able to support four human players, we implemented a turn-taking system and a check for valid piece-movement. We were even able to correctly detect and handle cases of check and check-mate.
We were unable to implement a basic computer AI nor were we able to finish two-player mode, but overall we were tremendously pleased with our progress and learned many valuable skills in team work and object-oriented programming.
New skills acquired:
- Object-Oriented Programming
- Basic graphics management
- Event Listeners
- Weekly Reports
- Presentation skills
- Team collaboration
We learned many new skills during this project - both in project management and in programming practices. The largest hurdles for me was learning how to utilize source control (SVN) and the principles of object-oriented programming.