private void SetupRoundHost()
        {
            //Create random board and serialize it.
            boardFactory.FillBoardStorageRandomly(boardStorage, ConfigurationType, boardManager);
            var message = boardFactory.ConvertBoardStorageToBytes(boardStorage);

            //Insert 'S' -- Setup leftParticipantId.
            message.Insert(0, setupMessageByte);
            //Send the board to the opponent.
            multiplayerController.SendMessage(message.ToArray());

            FinishSetup();
        }
Esempio n. 2
0
        /// <summary>
        /// Pings the opponent.
        /// 'P' -- ping message.
        /// </summary>
        /// <returns></returns>
        private IEnumerator WaitForOpponent()
        {
            waiting = true;
            var secondsPassed = 0;

            while (true)
            {
                if (!waiting)
                {
                    yield break;
                }
                var message = new[] { (byte)'P' };
                multiplayerController.SendMessage(message);
                secondsPassed++;
                if (secondsPassed > MAX_TIMEOUT_SECONDS)
                {
                    DisplayRoomSetupError();
                    yield break;
                }
                yield return(new WaitForSeconds(1));
            }
        }
        /// <summary>
        /// Pings the opponent every second until the max timeout.
        /// Solves the problem of loosing the very first message even between connected participants.
        /// </summary>
        /// <returns></returns>
        private IEnumerator WaitForOpponent()
        {
            waiting = true;
            var secondsPassed = 0;

            while (true)
            {
                if (!waiting)
                {
                    yield break;
                }
                var message = new[] { pingMessageByte };
                multiplayerController.SendMessage(message);
                secondsPassed++;
                if (secondsPassed > maxTimeoutSeconds)
                {
                    DisplayRoomSetupError();
                    yield break;
                }
                yield return(new WaitForSeconds(pingDeltaTimeSeconds));
            }
        }
Esempio n. 4
0
 public override void ProcessBoardClick(int x, int y)
 {
     byte[] message = { (byte)'M', (byte)'B', (byte)x, (byte)y };
     multiplayerController.SendMessage(message);
     base.ProcessBoardClick(x, y);
 }