Пример #1
0
        //ф-ия подключения клиента к серверу
        public bool Connect(string name)
        {
            if (!ValidateUserName(name))
            {
                return false;
            }

            Player player = new Player(name);
            player.Callback = OperationContext.Current.GetCallbackChannel<IClientServiceCallback>();

            NotifyPlayers(player, true);

            string sessionId = OperationContext.Current.SessionId;
            OperationContext.Current.Channel.Closing += (object sender, EventArgs args) =>
            {
                Player p = GetPlayerBySessionId(sessionId);
                if (p != null)
                {
                    _players.Remove(p);
                    _playerSessionMap.Remove(sessionId);
                    NotifyPlayers(p, false);
                }
            };

            _playerSessionMap[sessionId] = player;
            _players.Add(player);

            return true;
        }
Пример #2
0
 public void Turn(Player player, Player target)
 {
     if (OnTurn != null)
     {
         OnTurn(player, target);
     }
 }
Пример #3
0
 public void Fire(Player player, int col, int row)
 {
     if (OnFire != null)
     {
         OnFire(player, col, row);
     }
 }
Пример #4
0
 private void UpdateCompetitorField(Player player)
 {
     Field field = player.Field;
     UpdateField(this.DataGridView_CompetitorField, field, false);
 }
Пример #5
0
 //оповещаем всех пользователей о входе нового игрока
 private void NotifyPlayers(Player player, bool isEnter)
 {
     foreach (Player p in _players)
     {
         if (p.Name != _serverPlayer.Name && p.Name != player.Name)
         {
             IClientServiceCallback callback = p.Callback;
             callback.Message("Игрок " + player.Name + (isEnter ? " присоединился" : " отсоединился"));
         }
     }
 }
Пример #6
0
 private void NextPlayer()
 {
     do
     {
         _currentPlayerIndex = (_currentPlayerIndex + 1) % _players.Count;
         _currentPlayer = _players[_currentPlayerIndex];
     }
     while (_currentPlayer.IsDead);
     _targetIndex = -1;
     NextTarget();
 }
Пример #7
0
 public void SetServerPlayer(string name)
 {
     Player player = new Player(name);
     player.Callback = new ClientServiceCallback();
     _players.Add(player);
     _serverPlayer = player;
 }