Example #1
0
    private void DrawButtonsGUI(Rect screenPos, int userBoxWidth, int gameBoxWidth)
    {
        GUILayout.BeginArea(screenPos);
        GUILayout.BeginHorizontal();
        // Logout button
         	if (GUILayout.Button("Logout", buttonStyle, GUILayout.MaxWidth(userBoxWidth + 50)))
        {
            smartFox.Send(new LogoutRequest());
        }

        GUILayout.Space(screenPos.width - (userBoxWidth + gameBoxWidth + 125));

        // Game Room button
        if (GUILayout.Button("Make Game", buttonStyle, GUILayout.MaxWidth(gameBoxWidth + 125)))
        {
            if (currentActiveRoom.Name == "The Lobby")
            {

                Debug.Log("Make Game Button clicked");

                if (createdMyRoom)
                {
                    smartFox.Send(new JoinRoomRequest(username + " - Room", "", CurrentActiveRoom.Id));
                    return;
                }

                // ****** Create new room ******* //
                int gameLength = 120; //time in seconds

                //let smartfox take care of error if duplicate name
                RoomSettings settings = new RoomSettings(username + " - Room");
                // how many players allowed
                settings.MaxUsers = (short)maxPlayers;
                //settings.GroupId = "create";
                //settings.IsGame = true;

                List<RoomVariable> roomVariables = new List<RoomVariable>();
                //roomVariables.Add(new SFSRoomVariable("host", username));
                roomVariables.Add(new SFSRoomVariable("gameStarted", false));   //a game started bool

                SFSObject gameInfo = new SFSObject();
                gameInfo.PutUtfString("host", username);                        //the host
                SFSArray playerIDs = new SFSArray(); //[maxPlayers];

                gameInfo.PutSFSArray("playerIDs", playerIDs);                   //the player IDs
                gameInfo.PutInt("numTeams", numTeams);                          //the number of teams

                //hmmmmm
                SFSArray teams = new SFSArray();								//ASSIGN WHICH PLAYERS GO ON WHICH TEAMS
                int[] teamPlayerIndices;										// numTeams = 8, maxPlayers = 16
                for (int i = 0; i < numTeams; i++)								// i = 0, j = 0, j = 1, index = 0, index = 8
                {																// i = 1, j = 0, j = 1, index = 1, index = 9
                    teamPlayerIndices = new int[maxPlayers / numTeams];			// i = 2, j = 0, j = 1, index = 2, index = 10
                    for (int j = 0; j < maxPlayers / numTeams; j++)				// i = 3, j = 0, j = 1, index = 3, index = 11
                    { 															// ...
                        int index = i + (j * numTeams);
                        teamPlayerIndices[j] = index;							// i = 7, j = 0, j = 1, index = 7, index = 15
                    }

                    teams.AddIntArray(teamPlayerIndices);
                }
                gameInfo.PutSFSArray("teams", teams);                           //an array of possible values to be grabbed
                gameInfo.PutInt("gameLength", gameLength);                      //the length of the game

                roomVariables.Add(new SFSRoomVariable("gameInfo", gameInfo));

                settings.Variables = roomVariables;
                smartFox.Send(new CreateRoomRequest(settings, true, CurrentActiveRoom));           // Contains: maxUsers, and roomVariables
                createdMyRoom = true;
                Debug.Log("new room " + username + " - Room ");
            }
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
Example #2
0
    private void DrawUsersGUI(Rect screenPos)
    {
        GUILayout.BeginArea(screenPos);
        GUI.Box(new Rect(0, 0, screenPos.width, screenPos.height), "");
        GUILayout.BeginVertical();
        GUILayout.Label("Users");
        userScrollPosition = GUILayout.BeginScrollView(userScrollPosition, false, true, GUILayout.Width(screenPos.width));
        GUILayout.BeginVertical();
        List<User> userList = currentActiveRoom.UserList;
        foreach (User user in userList)
        {
            GUILayout.Label(user.Name);
        }
        GUILayout.EndVertical();
        GUILayout.EndScrollView();
        GUILayout.BeginHorizontal();
        // Logout button
        if (GUILayout.Button("Logout"))
        {
            smartFox.Send(new LogoutRequest());
        }
        // Game Room button
        if (currentActiveRoom.Name == "The Lobby")
        {
            if (GUILayout.Button("Make Game"))
            {
                Debug.Log("Make Game Button clicked");

                // ****** Create new room ******* //
                int gameLength = 120; //time in seconds

                //let smartfox take care of error if duplicate name
                RoomSettings settings = new RoomSettings(username + " - Room");
                // how many players allowed
                settings.MaxUsers = (short)maxPlayers;
                //settings.GroupId = "create";
                //settings.IsGame = true;

                List<RoomVariable> roomVariables = new List<RoomVariable>();
                //roomVariables.Add(new SFSRoomVariable("host", username));
                roomVariables.Add(new SFSRoomVariable("gameStarted", false));   //a game started bool
                // set up arrays of colors
                //SFSArray nums = new SFSArray();
                //for (int i = 0; i < 5; i++)
                //{
                //    nums.AddInt(i);
                //}
                //roomVariables.Add(new SFSRoomVariable("colorNums", nums));

                SFSObject gameInfo = new SFSObject();
                gameInfo.PutUtfString("host", username);                        //the host
                SFSArray playerIDs = new SFSArray(); //[maxPlayers];
                for (int i = 0; i < maxPlayers; i++)
                {
                    playerIDs.AddInt(i);
                }

                gameInfo.PutSFSArray("playerIDs", playerIDs);                   //the player IDs
                gameInfo.PutInt("numTeams", numTeams);                          //the number of teams

                SFSArray teams = new SFSArray();								//ASSIGN WHICH PLAYERS GO ON WHICH TEAMS
                int counter = 0;
                int[] teamPlayerIndices;										// numTeams = 8, maxPlayers = 16
                for (int i = 0; i < numTeams; i++)								// i = 0, j = 0, j = 1, index = 0, index = 8
                {																// i = 1, j = 0, j = 1, index = 1, index = 9
                    teamPlayerIndices = new int[maxPlayers / numTeams];			// i = 2, j = 0, j = 1, index = 2, index = 10
                    for (int j = 0; j < maxPlayers / numTeams; j++)				// i = 3, j = 0, j = 1, index = 3, index = 11
                    { 															// ...
                        int index = i + (j * numTeams);
                        teamPlayerIndices[j] = index;							// i = 7, j = 0, j = 1, index = 7, index = 15
                    }

                    teams.AddIntArray(teamPlayerIndices);
                }
                gameInfo.PutSFSArray("teams", teams);                           //an array of possible values to be grabbed
                gameInfo.PutInt("gameLength", gameLength);                      //the length of the game

                roomVariables.Add(new SFSRoomVariable("gameInfo", gameInfo));

                settings.Variables = roomVariables;
                smartFox.Send(new CreateRoomRequest(settings, true, CurrentActiveRoom));           // Contains: maxUsers, and roomVariables
                Debug.Log("new room " + username + "- Room");
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.EndVertical();
        GUILayout.EndArea();
    }