Codenjoy - CodingDojo framework for developers. Its goal is to organize fun teambuilding activities and/or train how to code. Already now we have a lot of games on board. And you can write one that will be your own.
All you need to develop a game is jdk8, maven3, git, and IDE Idea.
- install a git client locally, for example, tortoise git
- create an account on github or bitbucket
- make a fork (or copy the sample project) from the current repository
- pull the project to your computer
- install maven3 (download the archive and unzip it to
c:\java
) - add the
M2_HOME
environment variable that points to the root ofc:\java\apache-maven-3.x.x
- add the
;%M2_HOME%\bin
string at the end of thePath
variable - install jdk8, if necessary (also to the folder
c:\java
) - add the
JAVA_HOME
environment variable that points to the root ofc:\java\jdk1.8.x_xx
- add the
;%JAVA_HOME%\bin
string at the end of the Path variable - check by running cmd.exe with the
mvn -version
command. If installation is successful, you will see the command output the version of aven and java, rather than "command not found"
C:\Users\user>mvn -version
Apache Maven 3.x.x
Maven home: C:\java\apache-maven-3.x.x
Java version: 1.8.x_x, vendor: Oracle Corporation
Java home: C:\java\jdk1.8.x_xx\jre
Default locale: xxxxx, platform encoding: xxxxxxx
OS name: "xxxxxxxxxx", version: "xxx", arch: "xxxxx", family: "xxxxxxx"
C:\Users\user>
- download and install IntelliJ IDEA Community version
- install Lombok plugin for idea
You have to install the engine
dependency located in the engine
folder.
Watch out: its version may be updated, so you will have
to update it and your game's source code. To do this:
- open the
CodingDojo/games/engine
folder - run
setup.bat
- make sure installation is successful - the dependency should be
installed under
C:\Users\<UserName>\.m2\repository\com\codenjoy\engine
Invent/recall a game that might interest others, does not involve following complicated rules, and people played it in childhood.
The game might have the same rules as the original, or might provide some variation. For example, you can turn a two-player game, such as the battleship, into a multiplayer game. Make sure the gamer will enjoy writing the AI algorithm (the challenges should be reasonably tough).
Do not hesitate to contact us If stumped, get in touch and we'll help you.
Then proceed to writing a model of the game you selected. The following section contains the required how-to.
Here is an example (in russian) of how a 'reversi'
model was written: part1,
part2,
par3.
You can investigate commits with this command
git log --oneline 71090be..8a12c53
Unit testing coverage is expected. It'd be still better to write the code following TDD, and if you don't know how watch this video (in russian).
And then email us. We'll arrange for code review if necessary. And once the model is ready, we'll integrate it to our framework, and help your arrange your first Codenjoy event.
Here is the repository https://github.com/codenjoyme/codenjoy-game. You should find out how to fork a project, how to commit in git.
Project Sample is a sample of a one-board game with all requisite artefacts. Learn how a project operates.
- import the
sample
project asmaven project
to Idea - run all tests; as they progress, you should observe the green bar
- get sample/src/test/java/com/codenjoy/dojo/sample/model/SampleTest.java and see how tests for games are written.
- get sample/src/main/java/com/codenjoy/dojo/sample and see what are the minimum code requirements for a new game.
- the package here sample/src/main/java/com/codenjoy/dojo/sample/client has client code, with a part of it to be sent to the player as a game template
- the package sample/src/main/java/com/codenjoy/dojo/sample/client/ai has your AI algorithm that will automatically connect to the player and play with him or her.
- all the rest is the game engine.
- before you can implement your new game, take some time to familiarize
yourself with the main interfaces and framework classes. All of them are
located in the dependency engine. You should be interested in these:
- engine/src/main/java/com/codenjoy/dojo/services/Game.java
- engine/src/main/java/com/codenjoy/dojo/services/Joystick.java
- engine/src/main/java/com/codenjoy/dojo/services/Printer.java
- engine/src/main/java/com/codenjoy/dojo/services/GameType.java
- engine/src/main/java/com/codenjoy/dojo/services/multiplayer/GameField.java
- engine/src/main/java/com/codenjoy/dojo/services/multiplayer/GamePlayer.java
- engine/src/main/java/com/codenjoy/dojo/services/Tickable.java
- engine/src/main/java/com/codenjoy/dojo/services/PlayerScores.java
- engine/src/main/java/com/codenjoy/dojo/services/Point.java
- engine/src/main/java/com/codenjoy/dojo/services/GamePrinter.java
- engine/src/main/java/com/codenjoy/dojo/services/EventListener.java
- engine/src/main/java/com/codenjoy/dojo/services/Dice.java
- engine/src/main/java/com/codenjoy/dojo/services/State.java
- engine/src/main/java/com/codenjoy/dojo/services/Direction.java
- engine/src/main/java/com/codenjoy/dojo/services/settings/Settings.java
- engine/src/main/java/com/codenjoy/dojo/client/AbstractBoard.java
- engine/src/main/java/com/codenjoy/dojo/client/Solver.java
- engine/src/main/java/com/codenjoy/dojo/client/ClientBoard.java
- all of these are basic interfaces/classes that you use to integrate the new game into the main framework (like inserting a cartridge into a Dendy console).
- explore their description in java docs for the interfaces and classes of the dependency engine and the project sample.
To develop your game, you don't have to write all classes from
scratch - just base it off the sample
project.
- copy the contents of the
sample
folder into themygame
folder (any name) and replace theSample
word toMyGame
word in all classes. - your goal is to have your code well covered with tests, so that we can trust it. That's why you should develop the game using TDD. If this is an unfamiliar concept, we recommend this book by Ken Beck.
- maven will automatically assemble the game source for the client
in a zip file, as shown here
sample-clients.zip
Note that the
pom.xml
file has amaven-antrun-plugin
section, where ant assembles this zip. It includes the pom.xml file, theElements
class from the model package, and everything from theclient
package except theai
package. - write a manual for the game, see an example here:
- draw sprites - square-like pictures that will serve as the basis for rendering the game in the browser. Normally, they are freely available on the net. Png files with sprites can be found in the folder sample/src/main/webapp/resources/sprite/sample/. Important! Sprite names are not random, they should be associated with enum fields sample/src/main/java/com/codenjoy/dojo/sample/model/Elements.java. All names should be lowercase
- then implement your bot by analogy with sample/src/main/java/com/codenjoy/dojo/sample/client/ai/AISolver.java
- run DryRunGame class to see how your game works. You can check your bot also.
public class DryRunGame {
public static void main(String[] args) {
new LocalGameRunner()
.with(new GameRunner())
.add(new KeyboardSolver(),
// new AISolver(new RandomDice()),
new Board())
.run();
}
}
- another way to check how it's works is run sample/src/test/java/com/codenjoy/dojo/sample/SmokeTest.java
- assemble a jar file by running the
mvn package
command in the sample folder root - the jar file will be
sample\target\sample-engine.jar
- email it to us at [email protected] with the
New game for codenjoy
subject - than we will make a code review and you can improve the game
- Thanks!
- renname
sample
folder toyour-game
- remove everything except
your-game
folder - commit this changes
- push it to GitHub
- then go to another folder (outside game proect)
git clone https://github.com/codenjoyme/codenjoy.git
cd codenjoy
git subtree add --prefix=CodingDojo/games2 https://github.com/yourgithub/your-game.git master
- renname
CodingDojo/games2
toCodingDojo/games
with accept merging of two folders git add CodingDojo/games2
git add CodingDojo/games/your-game
- in the
CodingDojo/server/pom.xml
file, add new profile according to the template specified in the comment. Profile name should represent game name for simplicity:
<!-- this is your new game
<profile>
<id>yourgame</id>
<activation>
<property>
<name>allGames</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>yourgame-engine</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
-->
- you must add a new game to the
CodingDojo/games/pom.xml
parent project in the modules section
<modules>
<module>games/engine</module>
<module>games/sample</module>
...
<module>games/yourgame</module> <!-- this is your new game -->
</modules>
git add .
- `git commit -m "[your-game] Added new game YourGame"
git push --all origin
- then you can run codenjoy with this game
- if everything is OK, please prepare Pull Request with your game
There are several ways how you can build a game in jar. Each of them is used for its specific purpose.
To package an existing java client into an executable jar, run the following command:
mvn clean compile assembly:single -DskipTests=true -DgitDir=. -Pjar-with-dependencies
Here the gitDir
parameter is used to specify the
location of the .git
directory. You can also use
-Pjar-with-dependencies,noGit
to skip git-info phase.
After assembly, a file <GAMENAME>-engine-exec.jar
will appear in target
so you can run it:
java -jar ./target/<GAMENAME>-engine-exec.jar "<CONNECTION_URL>"
Here the <GAMENAME>
is game name that you try to build.
Parameter <CONNECTION_URL>
is optional - you can override connection URL hardcoded inside YourSolver class
java -jar ./target/<GAMENAME>-engine-exec.jar "http://codenjoy.com:80/codenjoy-contest/board/player/3edq63tw0bq4w4iem7nb?code=1234567890123456789"
You can run the game without a codenjoy server so that it will fully communicate with the ws client, as if the server were up. This is useful during game development.
To do this, the game must be able to implement it. For example MollyMage game contains a startup class Main in which the game starts. If your game has the same file, you can run the command:
mvn clean compile assembly:single -DskipTests=true -DgitDir=. -Pjar-local
Here the gitDir
parameter is used to specify the
location of the .git
directory. You can also use
-Pjar-local,noGit
to skip git-info phase.
After assembly, a file <GAMENAME>-engine.jar
will
appear in target
so you can run it:
- for windows
java -jar -Dhost=127.0.0.1 -Dport=8080 -Dtimeout=1000 -DlogDisable=false -Dlog="output.txt" -DlogTime=true -DshowPlayers="2,3" -Drandom="random-soul-string" -DwaitFor=2 -Dsettings="{'boardSize':11, 'potionPower':7} <GAMENAME>-engine.jar"
- for linux
java -jar --host=127.0.0.1 --port=8080 --timeout=1000 --logDisable=false --log="output.txt" --logTime=true --showPlayers="2,3" --random="random-soul-string" --waitFor=2 --settings="{'boardSize':11, 'potionPower':7} <GAMENAME>-engine.jar"
Here:
<GAMENAME>
is game name that you try to build.host
is always127.0.0.1
port
any port you wanttimeout
milliseconds between tickslogDisable
disable log outputlog
log filelogTime
true if you want to print timestamp of each message in logshowPlayers
true if you want to print player id of each message in lograndom
pseudo random soul string - it will affect pseudo random. For same string soul pseudo random will work the same.waitFor
list of players that we are waiting for for before the startsettings
json of game settings