ColorPuzzle

This is a small game for that I haven't found a good name yet so I called it "ColorPuzzle".

It was created as a example project to learn the Java 2D API and Swing/Canvas.

You can find the source code on github: https://github.com/lestard/ColorPuzzle

Related Articles:

  • ColorPuzzleFX

    | tagged as
    Summary:

    Again, I have rewritten one of my old games with JavaFX. This time I've created a JavaFX version of my old java swing game ColorPuzzle (yes I know, the name isn't very creative). screenshot of the game The game mechanics are the same: You can switch the color of all fields under your control. Everytime you are switching the active color, all fields in the direct neighbourhood of your own fields with that same color are going under your control from now on. The goal is to bring all fields under your control with the fewest moves. Before you ask: Yes, the game idea is not my invention, there are many games of this type out there and my version is only a clone. I create games only because programming is fun and not to become the best game inventor :-) The code is available on github: https://github.com/lestard/ColorPuzzleFX.

    Grid Component

    While the development of the game I have encapsulated the logic for manipulating and drawing the grid and extracted it into it's own component. This way I was able to reuse the grid logic for other projects like SnakeFX. You can view the code for this grid component on github too (https://github.com/lestard/Grid) but it's not intended for wide usage at the moment as documentation and testing far from production ready. It's more like a playground for me. In another post I will describe the idea behind the grid component in more detail.

    MvvmFX

    Another reason to build the game was to create a simple example for our own UI framework MvvmFX.
    ...

  • Java Game ColorPuzzle

    | tagged as
    Summary:

    Today I like to show you a little java game I have written roughly a year ago. Back in that time I was looking at the Java-2D-API and Swing/Canvas and thought that the best way to learn this stuff is to write a little game. Thinking of an good example game idea was not that easy so I decided to recreate an existing JavaScript game that I had played some time ago. The problem is that I can't remember what the original name was and where I found this game. :-( screenshot The gameplay is easy: You have a grid of squares like a chessboard but not in black and white. Instead the squares are randomly filled with one of 7 colors. At the beginning the player has control over the square in the top left corner. With the buttons on the right (one for every color) you can change the color of the square(s) you control. When there is a square with the same color in the direct neighbourhood of one of your controlled squares, this square is now also controlled by you. When you now click on one of the color-buttons, all squares controlled by you are changing the color again. The aim of the game is to control all squares with as little clicks as possible. Like I said, the main reason to create the game was not to build a great new super game but to learn and exercise the programming language and framework. The game was working more or less but there was an exception with the painting of the component in rare cases. I wasn't able to find the real reason for this exception and so I haven't released the game. Since then I haven't worked on the game but some weeks ago I remembered the game and wanted to finish it. While looking at the code I found some code smells and bad design. When I would build a game like this from scratch today I would do many things differently. As the first task I was looking at the unit-tests: I replaced EasyMock with Mockito and changed all asserts to used FEST-Assert. After this I refactored many classes and splitted the code into smaller pieces. While I didn't know the concept of Dependency Injection back in the time I created the game, nowadays DI for me is one of the most important design patterns and so I modified the application to use CDI/WELD-SE. I changed the whole event-mechanism to also use the features of CDI-Events. With this modifications I was able to reduce the coupling between the components a lot. The last modification was to change the way the canvas is repainted. The old version was using a game-loop with a repaint-mechanism that was more suitable for games that need a high framerate. As this is not the case for this game I changed it to used the default repaint mechanism of the swing components and removed the game loop. The exception that irrirtated me at first was now gone and so I thought it would be the right time to "release" the game now. Another reason to create the game was the idea to create something like an "artificial intelligence" (of cause it's not realy intelligent or clever) that can solve the game. I liked to test many strategies to build AIs and let them play against each other. I created a "Bogo" algorithm that chooses a color at random (referring to BogoSort) and a "Bruteforce" algorithm that tries every available color. At the moment this artificial intelligence feature is disabled but probably in the future I will create a UI for this. Have fun with the game. Before I forget, of course the Code is free software under the GPL and can be seen on github. Feel free to look into it and tell me what you think.
    ...