コード例 #1
0
        /// <summary>
        /// Starts a new game.
        /// </summary>
        /// <param name="tokens">Client tokens for game.</param>
        /// <returns>Port of game.</returns>
        public int StartGame(int[] tokens)
        {
            if (!GameAvailable())
            {
                throw (new Exception("No game available in InstancePool."));
            }

            GameInstance game = IdleGameInstance[IdleGameInstance.Count - 1];

            // Move game instance from idle game to active game.
            lock (ActiveGameInstance)
            {
                lock (IdleGameInstance)
                {
                    IdleGameInstance.RemoveAt(IdleGameInstance.Count - 1);
                    ActiveGameInstance.Add(game);
                }
            }

            game.Tokens = tokens;
            game.Start();

            // Log
            Trace.WriteLine("Game Started on :" + game.Port.ToString());

            return(game.Port);
        }
コード例 #2
0
        /// <summary>
        /// Event handler for when a game ends.
        /// </summary>
        /// <param name="sender">Reference to GameInstance.</param>
        private void HandleEndGame(object sender)
        {
            GameInstance game = (GameInstance)sender;

            Trace.WriteLine("Game Ended on :" + game.Port.ToString());

            // Move game instance from active to idle
            lock (ActiveGameInstance)
            {
                lock (IdleGameInstance)
                {
                    ActiveGameInstance.Remove(game);
                    IdleGameInstance.Add(game);
                }
            }
        }