Exemplo n.º 1
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();
    }
Exemplo n.º 2
0
 public void UpdateLockedScore()
 {
     List<UserVariable> userVars = new List<UserVariable>();
     GameValues.numLocked++;
     GameValues.myScore += (valueNormal + valueLock);
     SFSArray scores = new SFSArray();
     scores.AddInt(GameValues.numCaptured);
     scores.AddInt(GameValues.numLocked);
     scores.AddInt(GameValues.numStolen);
     scores.AddInt(GameValues.myScore);
     userVars.Add(new SFSUserVariable("score", scores));
     smartFox.Send(new SetUserVariablesRequest(userVars));
 }
Exemplo n.º 3
0
 public void UpdateStolenScore()
 {
     Debug.Log("Stealing a side");
     List<UserVariable> userVars = new List<UserVariable>();
     GameValues.numStolen++;
     GameValues.myScore += (valueNormal + valueSteal);
     Debug.Log("Num Stolen: " + GameValues.numStolen);
     SFSArray scores = new SFSArray();
     scores.AddInt(GameValues.numCaptured);
     scores.AddInt(GameValues.numLocked);
     scores.AddInt(GameValues.numStolen);
     scores.AddInt(GameValues.myScore);
     userVars.Add(new SFSUserVariable("score", scores));
     smartFox.Send(new SetUserVariablesRequest(userVars));
 }
Exemplo n.º 4
0
    private void RemovePlayer(int id, int teamId)
    {
        SFSObject gameInfo = (SFSObject)currentActiveRoom.GetVariable("gameInfo").GetSFSObjectValue();
        SFSArray idsLeft = (SFSArray)gameInfo.GetSFSArray("playerIDs");

        //update room variable
        SFSArray returnInts = new SFSArray();
        returnInts.AddInt(GameValues.playerID);
        Debug.Log("here in stuff: " + returnInts.GetInt(0));
        for (int i = 0; i < idsLeft.Size(); i++)
        {
            returnInts.AddInt(idsLeft.GetInt(i));
            Debug.Log("here in stuff: " + returnInts.GetInt(i + 1));
        }

        for (int i = 0; i < currentIDs.Size(); i++)
        {
            if (currentIDs.GetInt(i) == id)
            {
                currentIDs.RemoveElementAt(i);
                break;
            }
        }

        currentTeams[teamId]--;

        //send back to store on server
        List<RoomVariable> rData = new List<RoomVariable>();
        gameInfo.PutSFSArray("playerIDs", returnInts);
        rData.Add(new SFSRoomVariable("gameInfo", gameInfo));
        smartFox.Send(new SetRoomVariablesRequest(rData));
    }