JavaRush /Java Blog /Random EN /New section of JavaRush - “Games”

New section of JavaRush - “Games”

Published in the Random EN group
We have great news! JavaRush has a new section - “Games” , which is now open to all users. Here each of you can write a full-fledged game with graphics and feel like a real game developer. At the moment, the section is in beta testing, so it is very important for us to hear your opinion on how to make it even cooler! Try it, test it, leave feedback and suggestions under this post! You will learn briefly about the main features of the “Games” section from our video. Enjoy!
Now we invite you to take a closer look at the capabilities of the new section and get answers to the main questions that may arise when writing game problems.

1. How to write games in JavaRush

As you already understand, JavaRush has a unique opportunity - writing games . They are significantly larger than ordinary tasks, and much more interesting. It’s interesting not only to write them, but also, um, to test them. If you know what we mean ;) Work in the JavaRush office was literally paralyzed for several days when we began the testing phase of game tasks :) Each game task is a project: a large task with two dozen subtasks. As you write the game, you will need to complete them sequentially. When the last subtask is done, your game is ready. It will use a very simple game engine called JavaRush . Working with it is no more difficult than with the console. A description of the game engine and examples of working with it can be found in this document .

2. Game engine capabilities

The playing field is divided by the game engine into cells. The minimum size is 3x3, the maximum is 100x100. Each cell can be painted a certain color and some text can be written in it. Also, for each cell the size and color of the text are set. The engine allows you to write handler methods for events such as “mouse button presses” and “keyboard presses”. Another interesting thing to note is the ability to work with a timer. You will learn more about this in the “Working with the timer” section. This “obvious engine” allows you to create very interesting games, as you will see for yourself. Want to check it out? Then read the next paragraph and start writing games.

3. Gaining access to the game

To get access to writing games, you need to go to the “Games” section on the JavaRush website, select the one you like and go to its page. New section of JavaRush - “Games” - 1There will be a button “ Write your solution ” - click it. New section of JavaRush - “Games” - 2Your WebIDE will open and you will start working on the first subtask of the game. Also, from this moment on, the game’s subtasks will become available to you in Intellij IDEA, through the plugin. New section of JavaRush - “Games” - 3If you are using Intellij IDEA , you will need to update the plugin. You can download the latest version of the plugin here . After updating the plugin, open the task list and select "Java Games Quest". New section of JavaRush - “Games” - 4Next, click on the available subtask: the Java Games module should appear in your project, and in it - the engine library and the code of your subtask. Further actions are the same as when solving other problems. Games can be written in either WebIDE or Intellij IDEA, whichever you prefer. But Intellij IDEA is still more convenient. And more professional. The choice is yours.

4. Publishing games in the application directory

When you finish writing a game, you can publish it in the Games-and-Apps directory on JavaRush. Just click the “Publish” button, and after half a minute your game will be added to the “Published Games” section . New section of JavaRush - “Games” - 5If you want to share your game implementation with friends or colleagues, nothing could be easier. Just send them a link to the personal page of the published game and let them play. Registration on JavaRush is not required for this. New section of JavaRush - “Games” - 6You, as the creator, can admire the number of gaming sessions. Just like the number of views on YouTube. The bigger, the better.

5. Game customization

Once you've finished writing the game, you can modify it. Want 2048 on a 5x5 field? Please. You are a programmer - you have a keyboard in your hands. Change the game as you wish. You can add something new altogether. For example, in the game Snake, the snake can slow down if it eats an apple while it is still fresh (within the first 5 seconds after it appears). At the same time, the apple can change color from red to green, or become a pear. Or suddenly your snake loves rabbits more than apples... In Minesweeper you can add a second life to the player, or, for example, an atomic bomb, which will “illuminate” cells within a radius of several cells. But remember: if you add files or graphics to your game other than through the game engine, it may not be published in the application directory. Not everything can be run in a browser, you know.

6. Useful documentation

So that you can get acquainted with the work of the JavaRush game engine (initializing the game, creating the playing field and working with graphics), event processing (working with the mouse, keyboard and timer), as well as refresh or learn the basic theory of Java, which will be useful in writing tasks - games (the first and second JavaRush quest), we have prepared several detailed documents:

7. Common problems

I'm on Linux and using OpenJDK. When starting the game, the compiler throws an error:
Error:(6, 8) java: cannot access javafx.application.Application
  class file for javafx.application.Application not found
What to do? Our game engine uses JavaFX, and OpenJDK does not have it installed by default. This needs to be fixed:
  1. At the command prompt, enter the command:sudo apt-get install openjfx

  2. After that, go to the project settings (alt+ctrl+shift+s) -> SDK's -> Classpath and click on the plus sign on the right. Select the jfxrt.jar file. It is located in the installed JDK at the path: <JDK_PATH>/jre/lib/ext/jfxrt.jar

  3. Click OK.

I have Java 11. I can't start the game. What to do? Java 11 doesn't have JavaFX. Therefore, when starting the game, the compiler will not be able to compile the game, and there will be an error. To fix the problem, you need to add JavaFX to the project:
  1. Download the JavaFX Windows SDK from https://gluonhq.com/products/javafx/ .

  2. Unpack the downloaded archive into any folder (preferably into the lib folder of the Games project).

  3. Open IDEA.

  4. In IDEA, go to the File -> Project Structure menu.

  5. Select the Libraries tab and click + -> Java.

    New section of JavaRush - “Games” - 7
  6. Specify the path to the unpacked javafx-sdk folder and select the lib folder

    New section of JavaRush - “Games” - 8
  7. Next, click OK and in a new window, add JavaFX to the Games module.

    New section of JavaRush - “Games” - 9
  8. Now a new library should appear, click Apply -> OK.

    New section of JavaRush - “Games” - 10
  9. To launch correctly, open the Run-> Edit Configuration menu and enter the command in the VM options field:

    New section of JavaRush - “Games” - 11
    --module-path ./lib/javafx-sdk-16/lib --add-modules=javafx.controls,javafx.fxml,javafx.base
    New section of JavaRush - “Games” - 11
  10. Next, in the same tab you need to add Application. To do this, click + -> Application

    New section of JavaRush - “Games” - 12
    1. Select the Games module
    2. Enter the path to the main class (in this case - SnakeGame)
    3. Add a VM options field
    4. New section of JavaRush - “Games” - 13
    5. Enter VM options in the same way as in point 9.

    Click Apply -> OK

    New section of JavaRush - “Games” - 14
  11. Launch the game.

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION