This is the first project I made in my class on 2D Game Engines. The first assignment was to simply make Tic-Tac-Toe, the game we all know and love. This turned out to be a little harder than I anticipated as everything draw on screen had to be done from scratch and I had to create my own system for displaying and positioning elements.
The Project is made entirely out of java with event handling and the creation of the game window achieved using Swing. Everything seen inside the window was painted using Java's Graphics2D object. Part of the fun of this project was that I had to create my own UI Kit for displaying and positioning elements.
The system uses bounding boxes for each element on screen. The positioning of elements is calculated as an offset x and y from the parent object's origin where x is some percentage of the parent's width and y is some percentage of the parent's height. An element's own x and y values are also percentages of its parent's x and y values. This made positioning elements quite easy. If you wanted an element to be positioned exactly in the center of its parent, just set its offset to be 25% x and y, and its size to be 50% x and y. This would push the origin of the element 25% percent into its parent, followed by the element taking 50% of its parent's width, and then the last 25% to the element's right and bottom.
The game implements all the basic rules of Tic-Tac-Toe
Player two wins!
It's a draw!
All the elements also support resizing. What took a little more work than I thought was getting the resizing of text to work just right. When a text box resizes it searches for the the font sizes that fits in both height and width by doing a binary search on the available font sizes. It finds the upper bound first by doubling the current font size until it doesn't fit.
Here we have the game in full screen mode.