Home
Projects

April 20, 2025

Crazy Eights Icon Java Logo Crazy Eights

Card game written in Java using the Swing library and Model-View-Controller design pattern.

Features

  • Single player vs. AI or networked multiplayer vs. friends in client/host configuration
  • Game event log and chat system
  • Custom sound effects and art (banner, icon, card backs)
  • Internationalization (available in French and English)

Skills Applied

  • GUI programming & design
  • MVC
  • OOP
  • Multithreaded application design
  • Socket programming with custom packet protocol
Screenshot Screenshot

Background

This program was written over ~15 weeks as part of my Java Application Programming course, taken in term 4 of my program. The course had students design a game from the ground-up, starting with brainstorming the UI, which I sketched on paper before designing properly using Figma and which I tied in with designing the use-case and UML diagrams: Crazy Eights UML diagram The cumulative assignment had a few caveats:

  • All classes and methods must include Javadoc
  • Usage of Lambda expressions/anonymous classes is forbidden
  • Must be available in English plus at least one additional language
  • Must include logic for play against AI opponents
  • Must include logic for networked play against actual people
  • A custom packet protocol must be used for communication between server/client
  • Must follow the Model-View-Controller design pattern
  • All classes/methods will be modeled with use-case diagrams and UML prior to implementation
  • Custom batch file for compilation into runnable .jar
  • Optional usage of Git to keep track of progress for extra marks

What I learned

This project was difficult, but fun. So far, this project has taught me the most, as it most closely resembled the lifecycle of a program: planning, drawing diagrams, writing code, debugging, documenting, releasing. I dedicated a large number of hours/week to this assignment, sometimes spending full-time work hours per week programming, on many occasions upwards of 8 hours each day.

GUI

I learned how to use the Swing library to effectively execute the GUI that I had sketched on paper and designed in Figma. I found this to be the easiest part of the project as Swing’s library is quite intuitive once you understand components and layout managers. My entire UI was around 600 lines of code, which I spent a significant amount of time organizing in an effort to increase its readability/maintainability.

AI

The core AI game logic came together quite quickly and presented a unique challenge: how do I control the flow of turns? I settled on a method where the player (that is, the user playing the game) is differentiated by AI players via a flag, and when the player takes a turn, it sets off a chain that tells the next player to take their turn, if they are an AI, recursively. The recursive method has a base-case of checking the next player’s turn in the queue, and if they are human, clearing the call stack and returning control to the player. I decided to give the AI rudimentary decision making abilities (randomly chooses a legal play), so I could implement difficulty settings for the AI in the future, as time-management was key in this project and AI difficulty was not a requirement.

Networking

The network code was a big hurdle in this project as it introduced new and strange bugs, while simultaneously exponentially increasing the time required to fix them. I was able to test each feature (chat, sending moves, connecting players) modularly, using the custom packet protocol I developed. The basic syntax is: playerID#playType#playInformation. The server/clients would parse the information contained in the packets (all Strings) and, based on the type of play and what information was tied to that play, could refresh their displays accordingly. In this configuration, the server contained the game logic for each of the connected players, and told them how/when to update their Views.

Internationalization

The game is available in English by default, as well as French.


Other fun features

Console log

In addition to being the chat window in multiplayer mode, the console as I refer to it in documentation serves the additional purpose of being a game log, where all game events are recorded in both single and multiplayer modes. I found this, in addition to the “turn direction indicator”, to be an effective way of determining who’s turn it was.

Dynamic Naming

I included a dynamic naming system for each AI player. In short, when an AI player is created, they randomly choose a name from a .txt file in the project folder. Names can be added/removed by the user at any time, and I thought it added a personal touch to each game, instead of having each AI player being named “AI_PLAYER”.

Dynamic Card Image Retrieval

Since the UI would be displayed differently based on who was playing in each “zone” of the game, I had to solve the problem of how cards should be displayed based on location and perspective. When a card object is created, it determines how it should be displayed, and then assembles a path to the proper image file and sets its image accordingly. In addition, the player’s cards are drawn with a border when they are moused-over, which I thought added to the visual feedback.

Sound Effects

While not a requirement of the assignment, I thought sound effects would help with UX, and so I used a free Sound Effects generator to generate sound effects I thought would match the given action attached to them. I planned on including music (and even wrote some using BeepBox, but ultimately decided not to include it just yet in the release version.

Custom Retro Font

I thought it would be interesting to give the program more of a personality by tying part of its aesthetic to a certain retro-feeling. I found a SNES typeface on Google (license included) and used that as the font for all displayed text.


Source Code: View on Github

Download (via GitHub release): Download .jar

Instructions: Requires Java 17 or later. Run java -jar CrazyEights.jar

© Home 2025