A singledeck multi-player cardgame simulator
First, check if you have Java installed on your computer.
- Download the latest release from https://github.com/vaslabs/cardgame/releases/
unzip service-1.0
and change directory to service-1.0cd service-1.0
You should be able to see 3 directories (bin, lib and decks)- Start the service with ./bin/service
You should see a message like that:
11:33:00.568 [CardGame-akka.actor.default-dispatcher-3] WARN cardgame.Guardian$ - Admin token is 642293d4-fd03-4249-9619-ea3f110932ec
That is the admin token that you can use to create games.
Now that you have the admin token you can create a game. That means that players will be able to join your game.
To create a game use the admin token in authorization. Example:
curl 'http://localhost:8080/games-admin' \
-H 'Accept: text/plain' \
-H 'Authorization: Bearer 642293d4-fd03-4249-9619-ea3f110932ec' \
--data-binary '{}' \
-X POST
And you'll get a game id. Example:
b9da8c63-ef9b-4b2d-9269-b0ed2f4dbaee
Now players can join your game.
It's very easy to join a game locally. The hard part comes when you want to play with players remotely. What you'll need:
- The game id
- A username
- The server location that runs your game.
For example, locally you can do:
curl 'http://localhost:8080/game/b9da8c63-ef9b-4b2d-9269-b0ed2f4dbaee/join?username=vaslabs' --data-binary '{}'
Now, how can someone join your game that you are running on your laptop?
The easiest thing to use is ngrok
which will create a reverse proxy process on your laptop and
give you a public link to share with your friends.
When you install ngrok do
./ngrok http 8080
This will give you an http and https link. Give your friends the https ngrok link to replace the localhost:8080 with.
The guide ends here. You need a few more things to play:
- A front end (easier than running some command line curl commands).
- Somewhere to host your images so you don't run out of ngrok connections.
The UI is available here .
Start the angular app with
ng serve
Visit from your browser http://localhost:4200 .
You can host this application with gh-pages or you can use my version here
Note that this is just a front end, it doesn't serve any images , it just gives a game board view and allows you to do the in-game actions.
In order to join a game add the game id, a username and the server (if you are running the server locally, http://localhost:8080 will work for you, otherwise if you are using ngrok give to your friends the ngrok url).
Once a game has been created you can use this link to help your friends join more easily:
http://localhost:4200/setup?game-id=b9da8c63-ef9b-4b2d-9269-b0ed2f4dbaee&server=https://0000000.ngrok.io
(The server is just an example, replace with your own publicly available hostname).
You will see the players list being populated as more of your friends join.
Now that you are ready you can start a game.
To start a game you need:
- A deck
- The game id
- A location for serving the images from your deck
- Your admin token
There's already a premade deck provided.
So let's start with that.
To start the game with the sample deck provided you can do:
curl --location --request PATCH 'localhost:8080/games-admin?game=514b2598-ac38-4a0e-889b-2e3e2505fb55&deck=ee61823d-3128-4c30-b0e7-8f2d0074da8a&server=https://vaslabs.github.io/cardgame-cdn' \
--header 'Authorization: Bearer 642293d4-fd03-4249-9619-ea3f110932ec'
This will start a game with the sample deck, shuffle and give 7 cards to each player and select the first player to start.
The player in green highlight starts first. In order for other players to do any actions, you need to click the select next
attached next to their username.
In order to create your own deck you need:
- Images in jpg format.
- A configuration
The configuration is a json file that has this information:
- How many copies of each card exist
- How the game starts
For example, if you have card hero.jpg and you want to give to each player at least one hero you can do it in the starting section
"startingRules": {
"exactlyOne": ["hero"],
"no": [],
"hand": 5
}
Once you click start, the shuffling rules will apply. This game is not build for complex logic it only gives the primitives for game creation. You can improvise to play more games and even combine with other online platforms such as online drawing tools and video calls to play more board games.
-
Game admin creating games
-
Multiple players can join the game
-
Game admin starts the game with a deck and starting rules (initial player hand, initial restrictions)
-
Actions supported:
- Draw cards (from top and bottom)
- Borrow cards from deck (must be returned by end of turn)
- Players switching turns
- Stealing cards from each other
- Throwing cards to discard pile
- Retrieving cards from discard pile
- Throwing dice
- Shuffling hand
- Returning a card back to deck at any position, face up or face down
- Players can leave the game if they have an empty hand
- Players can switch direction of play (just indicative)
-
Actions and results are communicated via a websocket