# The Play Game Elements
Make sure you have all you need before proceeding:
- You understand the concepts of transactions, messages), and Protobuf.
- Have Go installed.
- The checkers blockchain codebase with
MsgCreateGame
and its handling. You can get there by following the previous steps or checking out the relevant version (opens new window).
To play a game a player only needs to specify:
- The ID of the game the player wants to join. Call the field
idValue
. - The initial positions of the pawn. Call the fields
fromX
andfromY
and make themuint
. - The final position of the pawn after a player's move. Call the fields
toX
andtoY
to beuint
too.
The player does not need to be explicitly added as a field in the message because the player is implicitly the signer of the message. Name the object PlayMove
.
Unlike when creating the game, you want to return:
- The game ID again. Call this field
idValue
. - The captured piece, if any. Call the fields
capturedX
andcapturedY
. - The winner in the field
winner
.
# With Starport
Now Starport only creates a response object with a single field. You can update the object after Starport has run:
Starport once more creates all the necessary Protobuf files and the boilerplate for you. All you have left to do is:
Add the missing fields to the response in
proto/checkers/tx.proto
:Use
int64
here so that you can enter-1
when no pawns have been captured.Fill in the needed part in
x/checkers/keeper/msg_server_play_move.go
:Where the
TODO
is replaced as per below.
# The move handling
rules
represent the ready-made file containing the rules of the game you imported earlier. Declare them in x/checkers/types/errors.go
given your code has to handle new error situations:
Take the following steps to replace the TODO
:
Fetch the stored game information:
Using the
Keeper.GetStoredGame
(opens new window) function created by Starport.Is the player legitimate? Check with:
Using the certainty that the
MsgPlayMove.Creator
has been verified by its signature (opens new window).Instantiate the board to implement the rules:
Good thing you previously created this helper (opens new window).
Is it the player's turn? Check with:
Using the rules file's own
TurnIs
(opens new window) function.Properly conduct the move:
Again using the rules proper
Move
(opens new window) function.Prepare the updated board to be stored and store the information:
Updating the fields that were modified using the
Keeper.SetStoredGame
(opens new window) function just as when you created and saved the game.Return relevant information regarding the move's result:
The
Captured
andWinner
information would be lost if you do not. More accurately, one would have to replay the transaction to find out the values. Better be a good citizen and make this information easily accessible.
That is all there is to it: good preparation and the use of Starport.
# Next up
Before you add a third Message to let a player reject a game, add events to the existing message handlers for relevant information. That is the object of the next section.
If you want to skip ahead and see how you can assist a player in not submitting a transaction that would result in a failed move, you can create a query to test a move.