Esempio n. 1
0
        /// <summary>
        /// Connects <see cref="TcpClient"/>s to the socket.
        /// </summary>
        void StartCommunication()
        {
            SocketHandler handler = (SocketHandler)SocketHandler;

            clientList = new List <User>();
            GoFishController gfc = new GoFishController(SocketHandler);

            // Start socket connection thread and update every second
            ConnectionListener(handler, gfc);
        }
Esempio n. 2
0
        /// <summary>
        /// Waits for enough connected <see cref="User"/> to start a <see cref="CardGame"/>
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="gfc"></param>
        private void ConnectionListener(SocketHandler handler, GoFishController gfc)
        {
            lock (_lock)
            {
                Thread connectionThread = new Thread(handler.HandleConnections);
                connectionThread.Start();
                while (true)
                {
                    Thread.Sleep(1000);

                    // Start game when there are two connected clients.
                    if (handler.GetClients().Count >= 3)
                    {
                        clientList = handler.GetClients();
                        gfc.NewGame(clientList);

                        gfc.SetStartPlayer(gfc.Games.Last());
                        break;
                    }
                }
            }
        }