public void distributePot(WinStatus winner) { stage = GameStage.DISTRIBUTE_POT; Winner = winner; if (winner == WinStatus.PLAYER_HUMAN) { HumanPlayer.Money += Pot; } else if (winner == WinStatus.PLAYER_ROBO) { RoboPlayer.Money += Pot; } else { RoboPlayer.Money += 20; HumanPlayer.Money += 20; } if (GameListener != null) { GameListener.PostDsitributePot(); } }
public MultiPlayer(Level level, int randomSeed, StatsTracker stats, GameListener listener) { this.stats = stats; this.listener = listener; one = new SinglePlayer(PlayerIndex.One, level, new Random(randomSeed), false, this); two = new SinglePlayer(PlayerIndex.Two, level, new Random(randomSeed), false, this); }
public void AddGameListener(GameListener listener) { if (!GameListeners.Contains(listener)) { GameListeners.Add(listener); } }
public static void addListener(GameListener listener) { if (!listeners.Contains(listener)) { listeners.Add(listener); } }
public void Attach(GameListener gameListener) { if (!gameListeners.Contains(gameListener)) { gameListeners.Add(gameListener); } }
public void Subscribe(GameListener listener) { lock (thisLock) { GameListener = listener; } }
public static void removeListener(GameListener listener) { if (listeners.Contains(listener)) { listeners.Remove(listener); } }
public void UnregisterListener <T>(Guid guid) where T : EventInfo { Debug.Log("Unregister: " + guid); System.Type eventType = typeof(T); if (eventListeners == null) { eventListeners = new Dictionary <System.Type, List <GameListener> >(); } if (eventListeners.ContainsKey(eventType) == false || eventListeners[eventType] == null) { eventListeners[eventType] = new List <GameListener>(); } // Find gameListenter in the dictionary to remove it GameListener gl = eventListeners[eventType].Where(x => x.guid == guid).FirstOrDefault(); if (gl == null) //no gamelistenter with that Guid, just leave.. { return; } eventListeners[eventType].Remove(gl); Debug.Log(guid + " unregistered"); }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> public Device() { this.GameListener = new ClientGameListener(this); this.NetworkManager = new NetworkManager(this); this.Defines = new Defines(); // Prepare.. }
public void endGame() { stage = GameStage.GAME_END; if (GameListener != null) { GameListener.OnGameEnd(); } }
public static void TestHomeportParse() { var provider = new UnitTestProvider(); var gameListener = new GameListener(new UnitTestProviderSelector(provider)); var navalBase = new NavalBase(gameListener, null, null); using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015208.676_START2.json")) provider.Push("api_start2", DateTimeOffset.Now, default, stream);
private GameMode(BattleSession session) { this.m_session = session; this.m_logicWatch = new Stopwatch(); this.m_logicGameMode = new LogicGameMode(); this.m_serverCommandStorage = new ServerCommandStorage(this, this.m_logicGameMode); this.m_gameListener = new GameListener(this); this.m_logicGameMode.GetLevel().SetGameListener(this.m_gameListener); this.m_logicGameMode.GetCommandManager().SetListener(this.m_serverCommandStorage); }
public static void StartListener() { GameListener listener = new GameListener(10, 1024 * 1024); listener.AcceptCompleted += AcceptCompleted; listener.ReceiveCompleted += ReceiveCompleted; listener.DisconnectCompleted += DisconnectCompleted; listener.Start(6650); Console.ReadKey(); }
static void Main(string[] args) { GameListener listener = new GameListener(10); listener.AcceptCompleted += AcceptCompleted; listener.ReceiveCompleted += ReceiveCompleted; listener.DisconnectCompleted += DisconnectCompleted; listener.Start(6650); Console.ReadKey(); }
static MasterDataTest() { var provider = new UnitTestProvider(); var gameListener = new GameListener(new UnitTestProviderSelector(provider)); masterData = new MasterDataRoot(gameListener, null); gameListener.MasterDataUpdated += (_, u) => parseResult = u; using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(MasterDataTest), "Data.masterdata.json")) provider.Push("api_start2", DateTimeOffset.Now, default, stream);
public static void LoadData(TestContext context) { var provider = new UnitTestProvider(); var gameListener = new GameListener(provider); masterData = new MasterDataRoot(gameListener, null); gameListener.MasterDataUpdated += (_, u) => parseResult = u; using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(MasterDataTest), "Data.masterdata.json")) provider.Push("api_start2", DateTimeOffset.Now, string.Empty, stream); }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> /// <param name="Token">The token.</param> public Device(NetworkToken Token) { this.NetworkManager = new NetworkManager(this); this.Token = Token; this.Token.SetDevice(this); Device Server = new Device(); this.GameListener = new ServerGameListener(Server); Server.GameListener = new ClientGameListener(this); Server.Connect("game.clashroyaleapp.com"); }
public SinglePlayer(PlayerIndex player, Level level, Random random, bool singlePlayer, GameListener listener) { this.player = player; this.level = level; this.random = random; this.singlePlayer = singlePlayer; this.listener = listener; this.paused = false; this.otherPaused = false; nextTokenReadiness = 0.0f; board = new Board(); tokenGenerator = new TokenGenerator(board, level, random); dumps = new CellColor[Constants.COLUMNS]; matches = new List<CellColor>(); state = State.SETTING_UP_BOARD; pauseMenu = new Menu(singlePlayer || (player == PlayerIndex.One), singlePlayer || (player == PlayerIndex.Two), delegate() { paused = false; listener.OnPaused(player, paused); }); pauseMenu.Add("Continue", delegate() { paused = false; listener.OnPaused(player, paused); }); pauseMenu.Add("Exit", delegate() { paused = false; otherPaused = false; listener.OnPaused(player, false); listener.OnFinished(player, null); }); wonMenu = new Menu(singlePlayer || (player == PlayerIndex.One), singlePlayer || (player == PlayerIndex.Two), delegate() { }); wonMenu.Add("Continue", delegate() { listener.OnFinished(player, null); }); wonMenu.Add("Retry", delegate() { listener.OnFinished(player, level); }); wonMenu.Add("Exit", delegate() { listener.OnFinished(player, null); }); failedMenu = new Menu(singlePlayer || (player == PlayerIndex.One), singlePlayer || (player == PlayerIndex.Two), delegate() { }); failedMenu.Add("Retry", delegate() { listener.OnFinished(player, level); }); failedMenu.Add("Exit", delegate() { listener.OnFinished(player, null); }); }
public void TestHomeportParse() { var provider = new UnitTestProvider(); var gameListener = new GameListener(provider); var navalBase = new NavalBase(gameListener, null); using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015208.676_START2.json")) provider.Push("api_start2", DateTimeOffset.Now, string.Empty, stream); using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015210.298_REQUIRE_INFO.json")) provider.Push("api_get_member/require_info", DateTimeOffset.Now, string.Empty, stream); using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(typeof(MasterDataTest), "Data.port.2018-05-28_015212.349_PORT.json")) provider.Push("api_port/port", DateTimeOffset.Now, string.Empty, stream); }
public override void OnStartClient() { if (instance) { Debug.LogError("ERROR: Another GameSession!"); } instance = this; networkListener = FindObjectOfType <GameListener>(); networkListener.gameSession = this; if (gameState != GameState.Lobby) { gameState = GameState.Lobby; } }
public void setupGame() { GameTurns += 1; stage = GameStage.SETUP; if (HumanPlayer.Money <= 0 || RoboPlayer.Money <= 0) { //Should not be needed since winner of the last round does not lose money /* if (RoboPlayer.Money < 0) * { * Winner = WinStatus.PLAYER_HUMAN; * } * else if (HumanPlayer.Money < 0) * { * Winner = WinStatus.PLAYER_ROBO; * }*/ endGame(); return; } else { Pot = 20; HumanPlayer.Money -= 10; RoboPlayer.Money -= 10; HumanPlayer.Hand = null; RoboPlayer.Hand = null; GameDealer.ShuffleAndDealDeck(HumanPlayer, RoboPlayer); HumanPlayer.Hand = HoldemHand.ChooseBestHand(HumanPlayer.HandCards, GameDealer.CommunityCards); RoboPlayer.Hand = HoldemHand.ChooseBestHand(RoboPlayer.HandCards, GameDealer.CommunityCards); HumanPlayer.HandChances = HoldemHand.TestHandChances(HumanPlayer.Hand, HumanPlayer.HandCards, GameDealer); RoboPlayer.HandChances = HoldemHand.TestHandChances(RoboPlayer.Hand, RoboPlayer.HandCards, GameDealer); } if (GameListener != null) { GameListener.PostGameSetup(); } sendPlayerTurn(); }
public ApiDebugView(GameListener provider) { this.InitializeComponent(); provider.RegisterAny().Received += async(timeStamp, obj) => await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Sessions.Add(new Message { Name = obj.Name, TimeStamp = timeStamp, Body = obj.Response }); while (Sessions.Count >= 50) { Sessions.RemoveAt(0); } }); }
// Second option to unregister, I don't think this is the most performatic way, however we can access it with less code. public void UnregisterListener(Guid guid) { if (eventListeners == null) { return; } KeyValuePair <Type, List <GameListener> > listener = eventListeners.Where(x => x.Value.Any(y => y.guid == guid)).FirstOrDefault(); GameListener gameListener = listener.Value.Where(x => x != null && x.guid == guid).FirstOrDefault(); if (gameListener == null)//no gamelistenter with that Guid, just leave.. { return; } eventListeners[listener.Key].Remove(gameListener); }
public async Task GameListener_CallsNewConnectionEvent() { const ushort AnyEphemerealPort = 7171; const int ExpectedConnectionCount = 1; const int NewConnectionsToEmulate = 1; TimeSpan waitForConnectionDelay = TimeSpan.FromSeconds(2); Mock <ILogger> loggerMock = new Mock <ILogger>(); Mock <IDoSDefender> defenderMock = new Mock <IDoSDefender>(); Mock <ITcpListener> tcpListenerMock = this.SetupTcpListenerMock(NewConnectionsToEmulate); Mock <ISocketConnectionFactory> connectionFactoryMock = this.SetupSocketConnectionFactory(); GameListenerOptions gameListenerOptions = new GameListenerOptions() { Port = AnyEphemerealPort, }; IListener gameListener = new GameListener <ISocketConnectionFactory>( loggerMock.Object, Options.Create(gameListenerOptions), connectionFactoryMock.Object, defenderMock.Object, tcpListenerMock.Object); var connectionCount = 0; var listenerTask = gameListener.StartAsync(CancellationToken.None); gameListener.NewConnection += (connection) => { connectionCount++; }; // Delay for a second and check that the counter has gone up on connections count. await Task.Delay(waitForConnectionDelay).ContinueWith(prev => { Assert.AreEqual(ExpectedConnectionCount, connectionCount, "New connections events counter does not match."); }); }
public void RegisterListener <T>(System.Action <T> listener, ref Guid guid) where T : EventInfo { System.Type eventType = typeof(T); if (eventListeners == null) { eventListeners = new Dictionary <System.Type, List <GameListener> >(); } if (eventListeners.ContainsKey(eventType) == false || eventListeners[eventType] == null) { eventListeners[eventType] = new List <GameListener>(); } // Wrap a type converstion around the event listener // I'm betting someone better at C# generic syntax // can find a way around this. EventListener wrapper = (ei) => { listener((T)ei); }; GameListener gameListener = new GameListener(wrapper); eventListeners[eventType].Add(gameListener); guid = gameListener.guid; }
public SysCollector() { _singleton = this; Scenes.Add(new Scene()); this.Listener += this.DispatchData; }
public void AddListener(GameListener listener) { Listeners.Add(listener); }
public override void OnStartServer() { networkListener = FindObjectOfType <GameListener>(); gameState = GameState.Connecting; }
public void Detach(GameListener gameListener) { gameListeners.Remove(gameListener); }
public void RemoveGameListener(GameListener listener) { GameListeners.Remove(listener); }
public static void removeListner(GameListener lis) { listeners.Remove(lis); }
public void NotifyOnResponse(PokerPlayer player, PokerPlayer.PokerResponse response) { if (stage == GameStage.PLAYER_TURN && player == HumanPlayer) { if (response == PokerPlayer.PokerResponse.RAISE) { player.Money -= 10; Pot += 10; if (GameListener != null) { GameListener.OnPlayerResponse(response); } sendRoboTurn(); } else { if (GameListener != null) { GameListener.OnPlayerResponse(response); } distributePot(WinStatus.PLAYER_ROBO); } } else if (stage == GameStage.OPPONENT_TURN && player == RoboPlayer) { if (response == PokerPlayer.PokerResponse.RAISE) { RoboPlayer.Money -= 10; Pot += 10; int compare = HumanPlayer.Hand.CompareTo(RoboPlayer.Hand); WinStatus win; if (compare > 0) { win = WinStatus.PLAYER_HUMAN; } else if (compare < 0) { win = WinStatus.PLAYER_ROBO; } else { win = WinStatus.TIE; } if (GameListener != null) { GameListener.OnOpponentResponse(response); } distributePot(win); } else { if (GameListener != null) { GameListener.OnOpponentResponse(response); } distributePot(WinStatus.PLAYER_HUMAN); } } }
public SysCollector() { //singleton = new EventCollector(); this.Listener += this.DispatchData; }