You are currently browsing the code.timst() posts tagged: Game

Project: Pong Fight

Pong Fight (named like that because it was supposed to be AI vs AI) is a Java pong remake that I made during my sophomore year.

Part of our exams included creating 5 mini-projects illustrating the different skills that we acquired during the two years of our programme, including object-oriented programming, imperative programming, database integration, GUI-making and so forth. Most people made simple CRUD applications, and indeed this was the case of two of my 5 projects. The others included a very simple text encryption software, made 2 years earlier (thus being my first real project), and the Casio compiler that I already mentioned, which was even less completed then. And of course when I actually took the exam, the examiners, two old ladies, told me they “hadn’t time for games” and tested me on the filler CRUD software. I got a measly 13/20. What a bunch of dicks.

image du pong

A graphic designer I ain’t.

But back to Pong Fight. It was from a time where we transitioned from procedural programming to OOP, even though we used Java from the start. So yeah, for more than a year we had “static” and “public class” keywords floating around and had absolutely no idea what they did, except randomly generating errors. So when I started the project, everything was in the same class. After a while I divided it, but this was a bit like dividing the code in multiple files in C: every single var and method were static, and the whole thing was completely contrary to everything the language stand for. So when we eventually learned OOP, I tried to restructure it, but it was a massive endeavor, especially since I wasn’t exactly a Java expert then and didn’t want to destroy the project while refactoring (which I did. Multiple times).

* Handles checkbox-style menu
* @param x (int) : x position of the click event
* @param x (int) : x position of the click event
* @param size (int) : number of elements in the menu
public int checkboxMenu(int x, int y, int size) {
    for(int i = 0; i< size; i++) {
        if(x >= Main.settingsFile.getSizeX()/8 &&
           x <= Main.settingsFile.getSizeX()/8 + 40 &&
           y >= Main.settingsFile.getSizeY()/5 + i*50 &&
           y <= Main.settingsFile.getSizeY()/5 + 40 + i*50) {
             return i;

   return -1;

I made my own game “engine”, meaning that I had to reimplement everything from mouse events to menu widgets. It was fun.

The result is a bizarre accumulation of static elements, singletons and bona-fide classes and objects living in (relative) harmony. Another part of the game that was completely cobbled together was the features: at the beginning I wanted a simple pong game that two basic AIs could play together. But after a while I got caught in the project, and added player support, which meant I had to handle keyboard events. Then I added an (in-game) option panel, which meant that I had to handle mouse events and multiple screens. Then I added sounds. Then I added graphic options. Then I made it possible to resize the window. Then I added  the jewel in the crown: network support. I delved into the Socket javadoc and eventually managed to make my pong playable across two computer in our lab, and then added spectator support, so other computers could connect to a game and watch it. My fellow classmates (and more importantly, my teachers) were in awe, and I got 19/20 at our mock exam when I presented it.

Too bad I didn’t get to present it at the real thing.