Remember back in High School when you and a buddy got out a piece of graph paper, drew a grid of dots, and then proceeded to take turns connecting the dots to form boxes? Whoever had the most boxes at the end of the game won. Well, I implemented it in openGL! [
Update 3/3/2012. I’ve uploaded the project for you to play! See details at the bottom of this post for more Update 9/30/2012: Due to (unpopular) demand, I’ve let the hosted file expire. Hit me up if you want me to repost it!]
Playing is simple: You’re initially asked by a prompt how many dots across you want to build your grid with (The whole grid will be square, so only the length of one side is needed).
Here, Red has just scored a box and thus gets to play again. Blue is way ahead, but that’s about to change! When someone wins the game, I created a cool little win animation where fireworks come up from the bottom screen and explode.
Some notes about the project:
1. This was an early 2D project for my graphics course. As a result, I got a lot wrong before I got anything right. The clickable areas, drawing the boxes, displaying text. All that was really hard for a newbie.
2. When a box is created it makes a little grow/shrink animation that I think looks pretty cool.
3. The fireworks on the win screen probably took the longest out of any single task. I had to have a point rise up from the bottom, reach mid-screen, then render 100 or so dots in a random distribution around a circle. Each dot then had to simultaneously fall, shrink, and grow blacker as they faded out until they disappeared.
4. When a person wins, it’s displayed to the right of the scores in a randomly generated color. Snazzy!
Downloading and Playing
- Download the files from here.
- After you unzip the project, there should be an application named “DotsAndBoxes”, double-click that to start the program.
- The program will ask “How many dots?”, this is this size of your grid. Type 4 for a 4×4 grid, and 10 for a 10×10 grid.
- Players alternate turns, with Red always playing first. To draw a line, click the space where the line should be (between two points)
- If a player finishes a box, they get to draw another line.
- Whoever has the most boxes at the end wins! Enjoy!