Example #1
0
 /// <summary>
 /// Окончание игры
 /// </summary>
 /// <param name="g"></param>
 private void GameFinishedHandler(SBGame g)
 {
     using (_games.Write())
     {
         _games.Object.Remove(g.Id);
     }
     this.SendToAll(new MsgRemoveGame()
     {
         Id = g.Id
     });
 }
Example #2
0
        /// <summary>
        /// Начало игры
        /// </summary>
        /// <param name="c"></param>
        /// <param name="opponentId"></param>
        /// <param name="password"></param>
        private void BeginGameHandler(SBRemoteClient c, Guid opponentId, string password)
        {
            SBRemoteClient opponent;

            if (c.State == KnownClientState.Free || c.State == KnownClientState.Ready)
            {
                using (_knownClients.Read())
                {
                    if (!_knownClients.Object.TryGetValue(opponentId, out opponent))
                    {
                        opponent = null;
                    }
                }

                if (opponent != null)
                {
                    if (opponent.Password == password)
                    {
                        c.SetState(KnownClientState.InGame);
                        opponent.SetState(KnownClientState.InGame);

                        var g = new SBGame(c, opponent);
                        g.OnScoreChanged += gc => GameScoreChangedHalder(gc);
                        g.OnGameFinished += () => GameFinishedHandler(g);

                        using (_games.Write())
                        {
                            _games.Object.Add(g.Id, g);
                        }

                        this.SendToAll(new MsgNewGame()
                        {
                            Id      = g.Id,
                            PlayerA = g.PlayerA,
                            PlayerB = g.PlayerB
                        });
                    }
                    else
                    {
                        c.Send(new MsgChatMessage()
                        {
                            Text = "Неверный пароль!"
                        });
                    }
                }
            }
        }