コード例 #1
0
ファイル: Board.cs プロジェクト: Seipers/DotNet_coinche
 public bool addPlayer(ClientSide player)
 {
     if (team1.isFull() && team2.isFull())
     {
         return(false);
     }
     if (team1.size() <= team2.size())
     {
         team1.addPlayer(player);
         Console.WriteLine("[+] " + player.Name + " join team 1");
     }
     else
     {
         team2.addPlayer(player);
         Console.WriteLine("[+] " + player.Name + " join team 2");
     }
     if (team1.isFull() && team2.isFull())
     {
         lock (this)
         {
             Monitor.Pulse(this);
         }
     }
     return(true);
 }
コード例 #2
0
        private ClientSide getClientSideByConnection(Connection connection)
        {
            ClientSide ret = null;

            foreach (var user in waiting_room)
            {
                if (user.Socket == connection)
                {
                    ret = user;
                }
            }
            return(ret);
        }
コード例 #3
0
        public void FirstConnect(Connection connection)
        {
            var tmp = new ClientSide(connection);

            waiting_room.Add(tmp);
            var req = new ServerRequest();

            req.Opcode = OpCodeEnum.WELCOME;
            Thread.Sleep(1000);
            connection.SendObject("ServerRequest", req);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("[*] User added to waiting room");
            Console.WriteLine("[*] Witing room size : " + waiting_room.Count);
            Console.ForegroundColor = ConsoleColor.White;
        }
コード例 #4
0
        public void setName(ClientRequest resp, Connection connection)
        {
            ClientSide user = getClientSideByConnection(connection);

            if (user != null)
            {
                user.Name = resp.Name;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("[*] Name of new client : " + user.Name);
                Console.ForegroundColor = ConsoleColor.White;
                if (this._board.addPlayer(user))
                {
                    waiting_room.Remove(user);
                }
            }
        }
コード例 #5
0
 public bool addPlayer(ClientSide player)
 {
     if (P1 == null)
     {
         P1 = player;
     }
     else if (P2 == null)
     {
         P2 = player;
     }
     else
     {
         return(false);
     }
     return(true);
 }