Skip to content

codenjoyme/codenjoy-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create your own Codenjoy game

Introduction

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.

Set up a development environment

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 of c:\java\apache-maven-3.x.x
  • add the ;%M2_HOME%\bin string at the end of the Path variable
  • install jdk8, if necessary (also to the folder c:\java)
  • add the JAVA_HOME environment variable that points to the root of c:\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>

Install the codenjoy engine

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

Develop a game

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.

Sample

Project Sample is a sample of a one-board game with all requisite artefacts. Learn how a project operates.

Develop a new game

To develop your game, you don't have to write all classes from scratch - just base it off the sample project.

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 apofig@gmail.com with the New game for codenjoy subject
  • than we will make a code review and you can improve the game
  • Thanks!

Merge your game into codenjoy master

  • renname sample folder to your-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 to CodingDojo/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

Build options

There are several ways how you can build a game in jar. Each of them is used for its specific purpose.

Create java-client executable jar

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"

Run game engine in a simple mode

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 always 127.0.0.1
  • port any port you want
  • timeout milliseconds between ticks
  • logDisable disable log output
  • log log file
  • logTime true if you want to print timestamp of each message in log
  • showPlayers true if you want to print player id of each message in log
  • random 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 start
  • settings json of game settings

Other materials

For more details, click here

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published