1. Writing games on CodeGym

Writing games on CodeGym

There is probably no programmer who wouldn't like to write games. And while writing them is a lot more difficult than playing them, there's little that compares to the feeling of seeing a game being born right beneath your fingertips.

That's why we added the unique opportunity to write games on CodeGym. Not only are game tasks significantly larger than ordinary tasks, they are also much more interesting. And it is interesting not only to write them, but also to test them. If you know what I mean... 😉

The CodeGym office literally became paralyzed for several days when we started the testing phase for the game tasks 🙂

Each game task is a project divided into a couple dozen subtasks. In the process of writing a game, you will need to complete all the subtasks in order. When you write the last subtask, you will have a finished game.

The game itself will use the CodeGym game engine. Its main feature is that it is very simple. Working with it is no more difficult than working with the console. Below you will find a description of the game engine along with examples of working with it.

2. Brief description of the game engine

The game engine divides the entire playing field into cells. The minimum size is 3×3, and the maximum is 100×100.

Each cell can be painted a certain color and we can write some text in it. We can also set the text size and color for each cell.

The engine allows lets you write event handlers, i.e. methods for handling events such as "mouse button clicked" and "keyboard key pressed".

Another interesting feature is the ability to work with a timer. You will find more details about this in the lesson entitled "Working with the timer".

This "primitive engine" lets you create very interesting games, as you can see for yourself:

3. Accessing a game

To get access to a game task, you need to go to the "Games" section on the website, select the game you want, and go to its page. You will see a "Write your own solution" button. Click it.

Accessing to CodeGym Games

This will open WebIDE, where you can start working on the game's first subtask. Also, from now on, the game's subtasks will be available to you in IntelliJ IDEA (via the plugin).

Accessing to CodeGym Games2

If you are using IntelliJ IDEA, open the task list in the plugin and select the Games quest.

Accessing to CodeGym Games 4

Next, click on the available subtask: the Java Games module should appear in your project, and along with it the game engine library and the code of your subtask. After that, everything is the same as when solving other tasks.

Accessing to CodeGym Games 5

Games can be written in WebIDE or IntelliJ IDEA, whichever you prefer. That said, IntelliJ IDEA is more convenient. And more professional. The choice is yours.

4. Publishing games in the app catalog

When you've finished writing your game, you'll be able to publish your program in the catalog of games and apps on CodeGym. Just click the "Publish" button. About half a minute later, your game will be added to the "Published Games" section.

You can publish the game from WebIDE:

Or from the plugin:

If you want to share your game implementation with friends or colleagues, nothing could be easier. Just send them a link to the page dedicated to your published game. A CodeGym account is not required.

You can also share your game on social networks. To do this, use the "Share with friends" button

As the game's creator, you can delight in the number of times it is played. Just like the number of views on YouTube, the more the better.

5. Customizing your games

Once you've finished writing your game, you can modify it to your heart's content.

Want to play 2048 on a 5×5 field? Go for it. You are the programmer: you control the cards keyboard. Change your game however you want.

You can introduce something fundamentally new to the game. For example, in the Snake game, the snake might slow down if it eats an apple while it is still fresh (within the first 5 seconds after it appears). An apple could change color from red to green, or become a pear. Or perhaps the snake loves rabbits more than apples...

In Minesweeper, you could give an extra life to the player, or perhaps an atomic bomb that "reveals" the cells within a radius of several cells.

Here's what one of the popular mods of the Mars Lander game looks like: the game's creator added teleportation to it.

But be aware that if you manipulate files or graphics in your game other than through the game engine, it may not be able to be published in the app catalog. Not everything can be run in a browser, you know.