Tutorial: a turn-based game
Crosses is a world for two players in which the person plays tic-tac-toe against the agent Otto. The view you build in this tutorial draws the board, says whose turn it is and sends the moves of the person to the world. It also shows the winner and the score, starts new rounds, opens a menu that the back button closes and gives each finished round a link of its own.
What you will build
In the finished view you play X against Otto. After the end of a round Past rounds opens that round again with its last board.
What you will learn
- Who plays what (
myRoleand the other members of the world). - Whose turn it is according to the
dataof the world. - Moves sent as messages to a fake opponent that answers them.
- The winner in a banner and the score of the match.
- A new round as one of the actions of the rules.
- A menu that the back button closes through
onBack. - A link to a round with
setPathand the address at which your view opens. - The theme of the webapp, the edges of the phone and the errors of the calls.
Before you start
The tutorial assumes that you know how a view connects to its world and draws it again at every change (Quick start). Tutorial: the view of a world is the better first tutorial because this one goes quickly over what that one explains (the data of a fake world, messages, actions, the theme and the errors).
Each step has a complete example in React and in plain JavaScript that runs on a fake world written in the same file (Otto included) without an account or a network. The code of any step can go into your project as it is and grow from there. In React, copy useWorld once next to your components.
The steps
- Draw the board: the board drawn from the
dataof the world. - Players and turns:
myRole, the other player and whose turn it is. - Make a move: the moves sent as messages and the answer of Otto.
- The winner: the end of a round in a banner.
- A new round and the score: a new round as an action of the rules and the score from
data. - A menu and the back button: a panel that the back button closes.
- A link to a round:
setPathand the address at which your view opens. - Look and finish: the theme, the phone, the errors and a board for fingers.
Next steps
Start with step 1: Draw the board.