/// <summary> /// Добавляем игрока в текущую игру. /// </summary> public bool JoinGame(GameDescription game, MainSkyShootService player) { GameSession session = _gameSessions.Find(curGame => curGame.LocalGameDescription.GameId == game.GameId); SessionTable.Add(player.Id, session); return(session.AddPlayer(player)); }
protected virtual void PlayerDead(MainSkyShootService player) { if (player == null) { Trace.WriteLine("strange error"); return; } //player.GameOver(); //SomebodyDied(player); player.Disconnect(); //временно player.TeamIdentity.Members.Remove(player); }
public bool AddPlayer(MainSkyShootService player) { if (_gameObjects.Count >= LocalGameDescription.MaximumPlayersAllowed || IsStarted) { return(false); } _gameObjects.Add(player); LocalGameDescription.Players.Add(player.Name); if (_gameObjects.Count == LocalGameDescription.MaximumPlayersAllowed) { // Trace.WriteLine("player added"+player.Name); var startThread = new System.Threading.Thread(Start); startThread.Start(); } return(true); }
protected override void PlayerDead(MainSkyShootService player) { base.PlayerDead(player); if (player.TeamIdentity.Members.Count == 0) { _sessionTeamsList.Teams.Remove(player.TeamIdentity); } if (_sessionTeamsList.Teams.Count <= 1) { if (_sessionTeamsList.Teams.Count == 1) { List <AGameObject> remainingTeams = _sessionTeamsList.Teams.First().Members; Debug.Assert(remainingTeams.Count == 1); MainSkyShootService lastPlayer = remainingTeams.First() as MainSkyShootService; System.Console.WriteLine(lastPlayer.Name + " wins"); lastPlayer.Disconnect(); player.TeamIdentity.Members.Remove(lastPlayer); } // TODO: final screen? } }
/// <summary> /// Ищем игру, в которой находится игрок и удаляем его оттуда. /// </summary> public bool LeaveGame(MainSkyShootService player) { try { GameSession game; SessionTable.TryGetValue(player.Id, out game); var leavingPlayer = player; game.PlayerLeave(leavingPlayer); if (game.PlayersCount() == 0) { game.Stop(); System.Console.WriteLine("Game over."); _gameSessions.Remove(game); } SessionTable.Remove(player.Id); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Создаем новую игру /// </summary> public GameDescription CreateGame(GameMode mode, int maxPlayers, MainSkyShootService client, TileSet tileSet, int teams) { GameSession gameSession; if (mode == GameMode.Coop) { gameSession = new CoopSession(tileSet, maxPlayers, mode, _gameId, teams); } else if (mode == GameMode.Deathmatch) { gameSession = new DeathmatchSession(tileSet, maxPlayers, mode, _gameId, teams); } else { gameSession = new GameSession(tileSet, maxPlayers, mode, _gameId, teams); } _gameSessions.Add(gameSession); SessionTable.Add(client.Id, gameSession); _gameId++; gameSession.AddPlayer(client); return(gameSession.LocalGameDescription); }
public void PlayerLeave(MainSkyShootService player) { if (LocalGameDescription.Players.Contains(player.Name)) { LocalGameDescription.Players.Remove(player.Name); } else { return; } player.MeMoved -= SomebodyMoved; player.MeShot -= SomebodyShot; player.MeChangeWeapon -= SomebodyChangedWeapon; //Players.Remove(player); lock (_gameObjects) { // player.TeamIdentity.members.Remove(player); _gameObjects.Remove(player); } Trace.WriteLine(player.Name + " leaved game"); }