Skip to content

Latest commit

 

History

History
135 lines (87 loc) · 7.92 KB

start-match.md

File metadata and controls

135 lines (87 loc) · 7.92 KB

PlayFab - Multiplayer Tic-Tac-Toe - Start Match flow

Index

Summary

This document explains how the Start Match flow was designed.

This flow is the step that links the Lobby scene with the game scene, and makes sure players are ready to play the match.

Despite the fact that this process is implemented in both, the Quick Match, and the Match Lobby cases, there is a minimal difference: the Match Lobby process has one extra step, where the host will be in charge of starting the match by pressing a specific button.

Implementation

Match Lobby



In the Match Lobby case we have three main steps:

  • Step 01: Before the OnNetworkJoined event is triggered.
  • Step 02: Between the OnNetworkJoined event and the OnDataMessageReceived event.
  • Step 03: After the OnDataMessageReceived event.

Step 01: Before OnNetworkJoined event

In this part both the Host and Guest players are involved.

On one hand, the host will be in charge of creating the Match Lobby itself, which includes also the creation of the Party Network the game will be using for communicating the players. For more information on this, read the create match lobby documentation.

On the other hand, we have the guest who will be searching for a specific lobby, and then joining to it (for more information on this, check the search match lobby and join to match lobby documents). The most important thing to highlight here is that, as the guest is joining the Party Network related to the Match Lobby, he/she will be triggering the OnNetworkJoined event.

Step 02: Between OnNetworkJoined and OnDataMessageReceived events

This step starts after the host handles the OnNetworkJoined event through the OnRemotePlayerJoinedListener method from the MatchLobbyScene script.

In this case, the game will be in charge of updating the connected player list from the host's view, through the RenderList method from the MatchLobbyPlayerListPopulate script. It is also in charge of enabling the Start Match button.

NOTE: The Start Match button is only available in the host's view.



This button enables the host to start the match at will when the necessary conditions for starting it are met. The conditions are controlled through the StartMatchConditionsMet method from the MatchLobbyScene script, which is called by the OnRemotePlayerJoinedListener method.

NOTE: So far, we've only one condition, which is that there must be only two players in the lobby (host and guest).

When the host press this button, they will start the game, and also will send a PlayersReady message over the Party Network for notifying that all the players must start the game.

Step 03: After OnDataMessageReceived event

In this case, the guest will handle the OnDataMessageReceived event using the OnDataMessageNoCopyReceivedListener method. More specifically, it will be calling the ProcessPlayersReadyMessage, where the game will be started.

Quick Match



The StartMatch method purpose is to swap from the Lobby scene to the game scene after both players are ready to play. This validation is performed here, after we check the number of players we currently have in the network.

Both players, herein Player One and Player Two, will execute the StartMatch method in two different situations, regardless of whether they are in a Quick Match or Match Lobby game:

  • Player one: This is the network creator, he/she executes the method after handling the OnRemotePlayerJoined event (i.e. after player two joins the network).
  • Player two: This player executes the method after receiving the Players Ready notification from Player One, when he/she handles the OnDataMessageNoCopyReceived.

For more details, you can read the document about the quick match process.

Once both players have executed the StartMatch method both game instances enter into the flow described in the game flow document.