コード例 #1
0
        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();
            }
        }
コード例 #2
0
ファイル: MultiPlayer.cs プロジェクト: bklimt/MisterToken
 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);
 }
コード例 #3
0
 public void AddGameListener(GameListener listener)
 {
     if (!GameListeners.Contains(listener))
     {
         GameListeners.Add(listener);
     }
 }
コード例 #4
0
ファイル: Game.cs プロジェクト: TkRsln/Reversi
 public static void addListener(GameListener listener)
 {
     if (!listeners.Contains(listener))
     {
         listeners.Add(listener);
     }
 }
コード例 #5
0
ファイル: Receiver.cs プロジェクト: sionovd/TexasHoldem
 public void Attach(GameListener gameListener)
 {
     if (!gameListeners.Contains(gameListener))
     {
         gameListeners.Add(gameListener);
     }
 }
コード例 #6
0
ファイル: GameService.cs プロジェクト: hoge8086/MiniShogi
 public void Subscribe(GameListener listener)
 {
     lock (thisLock)
     {
         GameListener = listener;
     }
 }
コード例 #7
0
ファイル: Game.cs プロジェクト: TkRsln/Reversi
 public static void removeListener(GameListener listener)
 {
     if (listeners.Contains(listener))
     {
         listeners.Remove(listener);
     }
 }
コード例 #8
0
        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");
        }
コード例 #9
0
        /// <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..
        }
コード例 #10
0
 public void endGame()
 {
     stage = GameStage.GAME_END;
     if (GameListener != null)
     {
         GameListener.OnGameEnd();
     }
 }
コード例 #11
0
        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);
コード例 #12
0
        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);
        }
コード例 #13
0
ファイル: IOPCTest.cs プロジェクト: sy545633799/NetworkCore
        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();
        }
コード例 #14
0
        static void Main(string[] args)
        {
            GameListener listener = new GameListener(10);

            listener.AcceptCompleted     += AcceptCompleted;
            listener.ReceiveCompleted    += ReceiveCompleted;
            listener.DisconnectCompleted += DisconnectCompleted;
            listener.Start(6650);

            Console.ReadKey();
        }
コード例 #15
0
        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);
コード例 #16
0
ファイル: MasterDataTest.cs プロジェクト: CodeForCSharp/ing
        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);
        }
コード例 #17
0
        /// <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");
        }
コード例 #18
0
ファイル: SinglePlayer.cs プロジェクト: bklimt/MisterToken
        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);
            });
        }
コード例 #19
0
ファイル: HomeportTest.cs プロジェクト: CodeForCSharp/ing
        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);
        }
コード例 #20
0
    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;
        }
    }
コード例 #21
0
        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();
        }
コード例 #22
0
ファイル: ApiDebugView.xaml.cs プロジェクト: wbsdty331/ing
 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);
         }
     });
 }
コード例 #23
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);
        }
コード例 #24
0
        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.");
            });
        }
コード例 #25
0
        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;
        }
コード例 #26
0
ファイル: SysCollector.cs プロジェクト: dourabbit/CPipe
 public SysCollector()
 {
     _singleton = this;
     Scenes.Add(new Scene());
     this.Listener += this.DispatchData;
 }
コード例 #27
0
 public void AddListener(GameListener listener)
 {
     Listeners.Add(listener);
 }
コード例 #28
0
 public override void OnStartServer()
 {
     networkListener = FindObjectOfType <GameListener>();
     gameState       = GameState.Connecting;
 }
コード例 #29
0
ファイル: Receiver.cs プロジェクト: sionovd/TexasHoldem
 public void Detach(GameListener gameListener)
 {
     gameListeners.Remove(gameListener);
 }
コード例 #30
0
 public void RemoveGameListener(GameListener listener)
 {
     GameListeners.Remove(listener);
 }
コード例 #31
0
 public static void removeListner(GameListener lis)
 {
     listeners.Remove(lis);
 }
コード例 #32
0
        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);
                }
            }
        }
コード例 #33
0
ファイル: SysCollector.cs プロジェクト: dourabbit/CPipe
 public SysCollector()
 {
     //singleton = new EventCollector();
     this.Listener += this.DispatchData;
 }