Exemplo n.º 1
0
        public void ToggleReady(Socket userId)
        {
            MasterNetworkPlayer player = clientSockets[userId];

            player.ready = !player.ready;

            Console.WriteLine("Ready toggled! " + player.ready);

            Room room = GetRoom(player.id);

            room.Refresh();
            bool allReady = true;

            for (int i = 0; i < room.usersInRoom.Count; i++)
            {
                if (room.usersInRoom[i].ready == false)
                {
                    allReady = false;
                }
            }

            if (room.usersInRoom.Count < 3)
            {
                allReady = false;
            }

            if (allReady)
            {
                StartGame(room);
            }
        }
Exemplo n.º 2
0
    public void Connect(string username)
    {
        masterNetworkPlayer          = new MasterNetworkPlayer();
        masterNetworkPlayer.username = username;

        MasterClientManager.instance.Connect(ip, port);

        MasterClientManager.instance.SendNetworkUser(masterNetworkPlayer);
    }
Exemplo n.º 3
0
    void UpdateUI()
    {
        Room room = MasterClientManager.instance.GetRoom();

        if (room == null)
        {
            gameObject.SetActive(false);
            UIManager.instance.startScreen.gameObject.SetActive(true);
            return;
        }

        if (room.startedGame)
        {
            gameObject.SetActive(false);
            UIManager.instance.screenAll.gameObject.SetActive(true);
            return;
        }

        int    playerNeeded = 3 - room.usersInRoom.Count;
        string myName       = "";

        for (int i = 0; i < users.Length; i++)
        {
            MasterNetworkPlayer player = null;
            if (i < room.usersInRoom.Count)
            {
                player = room.usersInRoom[i];
            }

            if (player != null)
            {
                users[i].userName.text = player.username.ToString();

                if (player.ready)
                {
                    users[i].statusImage.sprite = readyIcon;
                }
                else
                {
                    users[i].statusImage.sprite = notReadyIcon;
                }

                if (player.id == MasterClientManager.instance.getId())
                {
                    myName = player.username;
                }
            }
            else
            {
                users[i].statusImage.sprite = waitingIcon;
                users[i].userName.text      = "Waiting...";
            }
        }

        gameDataText.text = "Room ID: " + room.roomId + "\n\n" + "We need " + playerNeeded + " player(s)";
    }
Exemplo n.º 4
0
        public void Response50(byte[] responseBytes, Socket fromSocket, int fromId)
        {
            Console.WriteLine("Recieved a 50: " + fromId + ": " + responseBytes.Length);
            MasterNetworkPlayer masterNetworkPlayer = ByteParser.ConvertToNetworkPlayer(responseBytes);

            _server.clientSockets[fromSocket]    = masterNetworkPlayer;
            _server.clientSockets[fromSocket].id = fromId;



            Console.WriteLine("Users info: " + _server.clientSockets[fromSocket].id + ", " + _server.clientSockets[fromSocket].username);
        }
Exemplo n.º 5
0
        public void CreateRoom(Socket fromSocket)
        {
            MasterNetworkPlayer masterNetworkPlayer = clientSockets[fromSocket];

            Room room = new Room(masterNetworkPlayer.id);

            room.roomId = random.Next(1, 9) + "" + random.Next(0, 9) + "" + random.Next(0, 9) + "" + random.Next(0, 9).ToString();
            while (rooms.Count(x => x.roomId == room.roomId) > 0)
            {
                room.roomId = random.Next(1, 9) + "" + random.Next(0, 9) + "" + random.Next(0, 9) + "" + random.Next(0, 9).ToString();
            }
            rooms.Add(room);
        }
Exemplo n.º 6
0
    public static byte[] ConvertNetworkPlayerToBytes(MasterNetworkPlayer list)
    {
        string jsonString = JsonConvert.SerializeObject(list);

        return(ConvertASCIIToBytes(jsonString));
    }
 public void SendNetworkUser(MasterNetworkPlayer player)
 {
     MasterMessaging.instance.SendMasterNetworkPlayer(player, 2, _client.ourId, 0, _client.clientSocket);
 }