Java Drinking Games

As promised in my intro, I am going to write a little about an annual challenge I give myself: Spring Break Drinking Games. It started out of necessity. We were on spring break, thinking of late night fun activities, and decided on a drinking game. We searched for cards to play Circle of Death, only to find that no one had brought cards and it was much too late to go to a store.  Having just recently learned my first java coding principles, I whipped out my laptop and spent a couple hours simulating our card game. The rest of my party loved playing on a screen so much that the tradition continued the next year (this time with Horse Races).

Circle of Death

Screen shot of Circle of Death

Screen shot of Circle of Death

Circle of Death was quick and dirty. I had just started learning code, and had no idea of good code practices. I manually wrote many things that should have been looped. I included way too many things in one class, and I basically eliminated any possibility of future alteration. But it works.

I used a CardDeck Class with variables for each image to draw a random card, then add that card to the “used pile”.

I then made UI classes (my first attempt at java UI) and a gameLogic class which took the drawn card and kept track of what was happening in the game.

If you want to look at the code (or play the game) my gitHub has all source code and a runnable jar file here.

Horse Races

Horse Races UI

Horse Races UI

By this point, I had gotten a little bit better at UI, so this game didn’t take nearly as long, and is much more visually appealing. On the backend, I switched to using arrays to store images and programmatically create Card objects, rather than randomly drawing an image. I also created a set of functions to simulate real card deck usage (splitting, reshuffling, and separating out specific cards). This allows me to use my cardDeck class for other applications, opening the game up for modification.

To take a look at these games, download from the gitHub link here.

 

 

My next couple posts will be about my current project-in-progress: a  robotic bartender.

2 comments

Leave a comment