Skip to content

5. Turn Process

Rafa Paradela edited this page May 28, 2023 · 14 revisions

TURN SEQUENCE

TTTServer/GameStream process turns

TODO: Introduction to TTTServer/GameStream process turns

Exercise 22:

⚠️ Before tackling this exercise: Check out this commit XXXXXX Commit 32 here

TODO: Exposition of the exercise 22

Client send new movements

In previous exercises, we prepared the WebSocket to listening to the Game events, and that way, the app reacts accordingly. But it's shown in the next diagram, we are not propagating the Msg.RequestNewMovement to the server via the WebSocket.

notitle

Exercise 23:

Part 1: Publish new movements through the WebSocket

In the file ScalaDaysClient.scala, implement the method:

def publishWs(playerId: PlayerId, gameId: GameId, movement: Movement, ws: WebSocket[F]): Cmd[F, Msg]

taking into account the following tips:

Tip 1: WS.publish

Tyrian.WebSocket implements the function def publish[Msg](message: String): Cmd[F, Msg]

Tip 2: ClientAction

The ClientAction that the server expects is Turn.

Tip 3: Turn encoder

turn.asJson.noSpacesSortKeys encodes a Turn into a String

Part 2: React to the event Msg.RequestNewMovement

In the file Update.scala, please react to the event Msg.RequestNewMovement(game, newMovement).

Tip 1: New Model

The Model evolves with a new Game, which has the state GameState.Processing and the list of movements includes the newMovement

Tip 2: New Cmd

We have to publish the new movement via WebSocket by calling scalaDaysClient.publishWs(playerId, game.gameId, newMovement, ws)

Client implement restart game

TODO: Introduction to Client implement restart game

Exercise 24:

TODO: Exposition of the exercise 24

Clone this wiki locally