public Game(IActionQueue actionQueue, IPieceProvider pieceProvider, string name, int maxPlayers, int maxSpectators, GameRules rule, GameOptions options, string password = null) { if (actionQueue == null) throw new ArgumentNullException("actionQueue"); if (pieceProvider == null) throw new ArgumentNullException("pieceProvider"); if (name == null) throw new ArgumentNullException("name"); if (maxPlayers <= 0) throw new ArgumentOutOfRangeException("maxPlayers", "maxPlayers must be strictly positive"); if (maxSpectators <= 0) throw new ArgumentOutOfRangeException("maxSpectators", "maxSpectators must be strictly positive"); if (options == null) throw new ArgumentNullException("options"); Id = Guid.NewGuid(); _actionQueue = actionQueue; _pieceProvider = pieceProvider; _pieceProvider.Occurancies = () => options.PieceOccurancies; Name = name; CreationTime = DateTime.Now; MaxPlayers = maxPlayers; MaxSpectators = maxSpectators; Rule = rule; Options = options; Password = password; State = GameStates.Created; _specialId = 0; _isSuddenDeathActive = false; _gameStatistics = new Dictionary<string, GameStatisticsByPlayer>(); _winList = new List<WinEntry>(); _suddenDeathTimer = new Timer(SuddenDeathCallback, null, Timeout.Infinite, 0); _voteKickTimer = new Timer(VoteKickCallback, null, Timeout.Infinite, 0); }
public void ClientChangeOptions(GameOptions options) { ExceptionFreeAction(() => _proxy.ClientChangeOptions(options)); }
public void OnGameOptionsChanged(GameOptions gameOptions) { ResetTimeout(); throw new NotImplementedException(); }
public void TestChangeOptionsPieceProviderOccuranciesModified() { GameOptions originalOptions = new GameOptions(); originalOptions.Initialize(GameRules.Custom); IGame game = CreateGame("game1", 5, 10, GameRules.Custom, originalOptions); game.Start(new CancellationTokenSource()); IClient client1 = CreateClient("client1", new CountCallTetriNETCallback()); game.Join(client1, false); GameOptions newOptions = new GameOptions(); newOptions.Initialize(GameRules.Standard); game.ChangeOptions(client1, newOptions); Assert.IsNotNull(PieceProvider.Occurancies); Assert.AreEqual(newOptions.PieceOccurancies, PieceProvider.Occurancies()); }
public void ClientChangeOptions(GameOptions options) { IClient client = ClientManager[ClientCallback]; if (client != null && HostClientChangeOptions != null) HostClientChangeOptions(client, options); }
public void ClientChangeOptions(GameOptions options) { SetCallbackAndAddress(); Host.ClientChangeOptions(options); }
public void TestChangeOptionsOkWhenWaitingGameStart() { GameOptions originalOptions = new GameOptions(); originalOptions.Initialize(GameRules.Custom); IGame game = CreateGame("game1", 5, 10, GameRules.Custom, originalOptions); game.Start(new CancellationTokenSource()); IClient client1 = CreateClient("client1", new CountCallTetriNETCallback()); game.Join(client1, false); GameOptions newOptions = new GameOptions(); newOptions.Initialize(GameRules.Custom); game.ChangeOptions(client1, newOptions); Assert.AreEqual(newOptions, game.Options); }
protected abstract IGame CreateGame(string name, int maxPlayers, int maxSpectators, GameRules rule, GameOptions options, string password);
private void OnGameOptionsChanged(GameOptions gameOptions) { Console.WriteLine("OnGameOptionsChanged"); }
public void TestChangeOptionsFailedIfNotGameMaster() { GameOptions originalOptions = new GameOptions(); originalOptions.Initialize(GameRules.Custom); IGame game = CreateGame("game1", 5, 10, GameRules.Custom, originalOptions); game.Start(new CancellationTokenSource()); IClient client1 = CreateClient("client1", new CountCallTetriNETCallback()); game.Join(client1, false); IClient client2 = CreateClient("client2", new CountCallTetriNETCallback()); game.Join(client2, false); GameOptions newOptions = new GameOptions(); newOptions.Initialize(GameRules.Custom); bool succeed = game.ChangeOptions(client2, newOptions); Assert.AreEqual(originalOptions, game.Options); Assert.IsFalse(succeed); }
public void OnGameOptionsChanged(GameOptions gameOptions) { ExceptionFreeAction(() => Callback.OnGameOptionsChanged(gameOptions)); }
protected override IGame CreateGame(string name) { GameOptions options = new GameOptions(); options.Initialize(GameRules.Standard); return new Game(new ActionQueueMock(), new PieceProviderMock(), name, 10, 10, GameRules.Standard, options); }
public bool ChangeOptions(GameOptions options) { _proxy.Do(x => x.ClientChangeOptions(options)); return true; }
public bool ChangeOptions(IClient client, GameOptions options) { if (State != GameStates.WaitStartGame) { Log.Default.WriteLine(LogLevels.Warning, "Cannot change options, game {0} is started", Name); return false; } if (client != null) { if (!client.IsPlayer) { Log.Default.WriteLine(LogLevels.Warning, "Cannot change options, {0} is not flagged as player", client.Name); return false; } if (client.Game != this) { Log.Default.WriteLine(LogLevels.Warning, "Cannot change options, {0} is not in game {1}", client.Name, Name); return false; } if (!client.IsGameMaster) { Log.Default.WriteLine(LogLevels.Warning, "Cannot change options, client {0} is not game master", client.Name); return false; } } if (!options.IsValid) { Log.Default.WriteLine(LogLevels.Warning, "Cannot change options, options are not valid"); return false; } // Options = options; _pieceProvider.Occurancies = () => Options.PieceOccurancies; // Inform clients foreach (IClient target in Clients) target.OnGameOptionsChanged(options); Log.Default.WriteLine(LogLevels.Info, "Game {0}: game options changed by {1}", Name, client == null ? "[SERVER]" : client.Name); return true; }
public void TestChangeOptionsClientsInformed() { GameOptions originalOptions = new GameOptions(); originalOptions.Initialize(GameRules.Custom); IGame game = CreateGame("game1", 5, 10, GameRules.Custom, originalOptions); game.Start(new CancellationTokenSource()); CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback(); IClient client1 = CreateClient("client1", callback1); game.Join(client1, false); CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback(); IClient client2 = CreateClient("client2", callback2); game.Join(client2, true); CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback(); IClient client3 = CreateClient("client3", callback3); game.Join(client3, false); GameOptions newOptions = new GameOptions(); newOptions.Initialize(GameRules.Custom); game.ChangeOptions(client1, newOptions); Assert.AreEqual(1, callback1.GetCallCount("OnGameOptionsChanged")); Assert.AreEqual(1, callback2.GetCallCount("OnGameOptionsChanged")); Assert.AreEqual(1, callback3.GetCallCount("OnGameOptionsChanged")); }
public void OnGameOptionsChanged(GameOptions gameOptions) { throw new NotImplementedException(); }
protected override IGame CreateGame(string name, int maxPlayers, int maxSpectators) { GameOptions options = new GameOptions(); options.Initialize(GameRules.Standard); return CreateGame(name, maxPlayers, maxSpectators, GameRules.Classic, options); }
protected override IGame CreateGame(string name, int maxPlayers, int maxSpectators, GameRules rule, GameOptions options, string password) { return new Game(new ActionQueueMock(), new PieceProviderMock(), name, maxPlayers, maxSpectators, rule, options, password); }
protected IGame CreateGame(IActionQueue actionQueue, IPieceProvider pieceProvider, string name, int maxPlayers, int maxSpectators, GameRules rule, GameOptions options, string password = null) { ActionQueue = actionQueue as ActionQueueMock; PieceProvider = pieceProvider as PieceProviderMock; return new Game(actionQueue, pieceProvider, name, maxPlayers, maxSpectators, rule, options, password); }
public void ClientChangeOptions(GameOptions options) { IClient client = ClientManager[ClientCallback]; if (client != null) HostClientChangeOptions.Do(x => x(client, options)); else Log.Default.WriteLine(LogLevels.Warning, "ClientChangeOptions from unknown client"); }
public void TestConstructorSetProperties() { const string name = "game1"; const int maxPlayers = 5; const int maxSpectators = 10; const GameRules rule = GameRules.Extended; const string password = "******"; GameOptions options = new GameOptions(); IGame game = new Game(new ActionQueueMock(), new PieceProviderMock(), name, maxPlayers, maxSpectators, rule, options, password); Assert.IsNotNull(game); Assert.AreEqual(name, game.Name); Assert.AreEqual(maxPlayers, game.MaxPlayers); Assert.AreEqual(maxSpectators, game.MaxSpectators); Assert.AreEqual(rule, game.Rule); Assert.AreEqual(options, game.Options); Assert.AreEqual(password, game.Password); Assert.AreNotEqual(Guid.Empty, game.Id); Assert.AreEqual(GameStates.Created, game.State); }
public void OnGameOptionsChanged(GameOptions gameOptions) { UpdateCallInfo(System.Reflection.MethodBase.GetCurrentMethod().Name, gameOptions); }
public IGame CreateGame(string name, int maxPlayers, int maxSpectators, GameRules rule, GameOptions options, string password) { return new Game(new BlockingActionQueue(), new PieceBag(RangeRandom.Random, 4), name, maxPlayers, maxSpectators, rule, options, password); }