Ejemplo n.º 1
0
 void Start()
 {
     pointTracker   = GetComponent <PointTracker>();
     roundTracker   = GetComponent <RoundTracker>();
     remainingLives = startingLives;
     Debug.Log("setting remaining lives in start");
 }
Ejemplo n.º 2
0
 public Setup_GS(
     Lobby lobby,
     RoundTracker roundTracker,
     int numExpectedPerUser,
     TimeSpan?setupDuration = null)
     : base(
         lobby: lobby,
         numExpectedPerUser: numExpectedPerUser,
         unityTitle: "Time To Write",
         unityInstructions: "Write your questions",
         setupDuration: setupDuration)
 {
     this.RoundTracker = roundTracker;
 }
Ejemplo n.º 3
0
        public CreateMimics_GS(Lobby lobby, RoundTracker roundTracker, TimeSpan?drawingTimeDuration = null) : base(lobby)
        {
            SelectivePromptUserState createMimics = new SelectivePromptUserState(
                usersToPrompt: lobby.GetAllUsers().Where((User user) => user != roundTracker.originalDrawer).ToList(),
                promptGenerator: (User user) => new UserPrompt()
            {
                UserPromptId = UserPromptId.Mimic_RecreateDrawing,
                Title        = Constants.UIStrings.DrawingPromptTitle,
                Description  = "Recreate the drawing you just saw to the best of your abilities",
                SubPrompts   = new SubPrompt[]
                {
                    new SubPrompt
                    {
                        Drawing = new DrawingPromptMetadata {
                            ColorList      = CommonConstants.DefaultColorPalette.ToList(),
                            GalleryOptions = null
                        }
                    }
                },
                SubmitButton = true
            },
                formSubmitHandler: (User user, UserFormSubmission input) =>
            {
                UserDrawing submission = new UserDrawing
                {
                    Drawing = input.SubForms[0].Drawing,
                    Owner   = user
                };
                roundTracker.UsersToUserDrawings.AddOrReplace(user, submission);
                return(true, string.Empty);
            },
                exit: new WaitForUsers_StateExit(
                    lobby: this.Lobby,
                    waitingPromptGenerator: (User user) => (user == roundTracker.originalDrawer)?Prompts.DisplayText("Others are recreating your masterpiece.  Enjoy the turmoil.")(user):Prompts.DisplayText("Waiting for others to finish mimicking.")(user)
                    ),
                maxPromptDuration: drawingTimeDuration);

            this.Entrance.Transition(createMimics);
            createMimics.Transition(this.Exit);

            this.Legacy_UnityView = new Legacy_UnityView(this.Lobby)
            {
                ScreenId = new StaticAccessor <TVScreenId> {
                    Value = TVScreenId.WaitForUserInputs
                },
                Instructions = new StaticAccessor <string> {
                    Value = "Recreate that drawing to the best of your abilities"
                },
            };
        }
Ejemplo n.º 4
0
    void Start()
    {
        if (rematch == null)
        {
            rematch = GetComponent <Image>().sprite;
        }

        roundTracker = GameObject.FindGameObjectWithTag("Finish").GetComponent <RoundTracker>();
        if (roundTracker.CheckIfWin())
        {
            image = rematch;
        }
        else
        {
            image = newRound;
        }

        GetComponent <Image>().sprite = image;
    }
Ejemplo n.º 5
0
    void Start()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
            totalRounds = GameStats.amountOfRounds;
            roundsToWin = Mathf.FloorToInt((totalRounds / 2f) + 1);
        }
        else
        {
            Destroy(gameObject);
        }

        if (wins.Length == 0)
        {
            wins = new int[totalRounds];
        }
    }
Ejemplo n.º 6
0
        private State GetVotingAndRevealState(RoundTracker roundTracker, TimeSpan?votingTime)
        {
            List <UserDrawing> drawings = roundTracker.UsersToDisplay.Select(user => roundTracker.UsersToUserDrawings[user]).ToList();
            int indexOfOriginal         = roundTracker.UsersToDisplay.IndexOf(roundTracker.originalDrawer);

            drawings[indexOfOriginal].ShouldHighlightReveal = true;

            return(new BlurredImageVoteAndRevealState(
                       lobby: this.Lobby,
                       drawings: drawings,
                       blurRevealDelay: MimicConstants.BlurDelay,
                       blurRevealLength: MimicConstants.BlurLength,
                       votingTime: votingTime)
            {
                VotingViewOverrides = new UnityViewOverrides
                {
                    Title = "Find the Original!",
                },
                VoteCountManager = CountVotes(roundTracker)
            });
        }
        public ContestantCreation_GS(Lobby lobby, RoundTracker roundTracker, TimeSpan?creationDuration)
            : base(
                lobby: lobby,
                exit: new WaitForUsers_StateExit(lobby))
        {
            this.RoundTracker = roundTracker;
            TimeSpan?multipliedCreationDuration = creationDuration.MultipliedBy(roundTracker.UsersToAssignedPrompts.Values.ToList()[0].Count);

            MultiStateChain contestantsMultiStateChain = new MultiStateChain(MakePeopleUserStateChain, stateDuration: multipliedCreationDuration);

            this.Entrance.Transition(contestantsMultiStateChain);
            contestantsMultiStateChain.Transition(this.Exit);

            this.Legacy_UnityView = new Legacy_UnityView(this.Lobby)
            {
                ScreenId = new StaticAccessor <TVScreenId> {
                    Value = TVScreenId.WaitForUserInputs
                },
                Instructions = new StaticAccessor <string> {
                    Value = "Make your contestants on your devices."
                },
            };
        }
Ejemplo n.º 8
0
 private void Awake()
 {
     roundTracker  = GetComponent <RoundTracker>();
     playerTracker = GetComponent <PlayerTracker>();
     scoreTracker  = GetComponent <ScoreTracker>();
 }
Ejemplo n.º 9
0
    private void Awake()
    {
        R = this;

        DontDestroyOnLoad(R);
    }
Ejemplo n.º 10
0
        public MimicGameMode(Lobby lobby, List <ConfigureLobbyRequest.GameModeOptionRequest> gameModeOptions, StandardGameModeOptions standardOptions)
        {
            GameDuration duration = standardOptions.GameDuration;
            int          numStartingDrawingsPerUser = 1;
            int          maxDrawingsBeforeVoteInput = (int)gameModeOptions[(int)GameModeOptions.MaxDrawingsBeforeVote].ValueParsed;
            int          maxVoteDrawings            = 12; // Everybody's drawing should show up, but it gets a little prohibitive past 12 so limit it here.
            TimeSpan?    drawingTimer = null;
            TimeSpan?    votingTimer  = null;

            if (standardOptions.TimerEnabled)
            {
                drawingTimer = MimicConstants.DrawingTimer[duration];
                votingTimer  = MimicConstants.VotingTimer[duration];
            }
            TimeSpan?extendedDrawingTimer = drawingTimer.MultipliedBy(MimicConstants.MimicTimerMultiplier);
            int      numPlayers           = lobby.GetAllUsers().Count();
            int      numRounds            = Math.Min(MimicConstants.MaxRounds[duration], numPlayers);

            this.Lobby = lobby;

            Setup = new Setup_GS(
                lobby: lobby,
                drawings: Drawings,
                numDrawingsPerUser: numStartingDrawingsPerUser,
                drawingTimeDuration: drawingTimer);
            List <UserDrawing> randomizedDrawings = new List <UserDrawing>();

            Setup.AddExitListener(() =>
            {
                randomizedDrawings = this.Drawings
                                     .OrderBy(_ => Rand.Next())
                                     .ToList()
                                     .Take(numRounds) // Limit number of rounds based on game duration.
                                     .ToList();
            });
            StateChain CreateGamePlayLoop()
            {
                bool       timeToShowScores = true;
                StateChain gamePlayLoop     = new StateChain(stateGenerator: (int counter) =>
                {
                    if (randomizedDrawings.Count > 0)
                    {
                        StateChain CreateMultiRoundLoop()
                        {
                            int maxDrawingsBeforeVote = Math.Min(maxDrawingsBeforeVoteInput, randomizedDrawings.Count);
                            if (randomizedDrawings.Count == 0)
                            {
                                throw new Exception("Something went wrong while setting up the game");
                            }
                            List <RoundTracker> roundTrackers = new List <RoundTracker>();
                            return(new StateChain(stateGenerator: (int counter) =>
                            {
                                if (counter < maxDrawingsBeforeVote)
                                {
                                    UserDrawing originalDrawing = randomizedDrawings.First();
                                    randomizedDrawings.RemoveAt(0);

                                    RoundTracker drawingsRoundTracker = new RoundTracker();
                                    roundTrackers.Add(drawingsRoundTracker);
                                    drawingsRoundTracker.originalDrawer = originalDrawing.Owner;
                                    drawingsRoundTracker.UsersToUserDrawings.AddOrUpdate(originalDrawing.Owner, originalDrawing, (User user, UserDrawing drawing) => originalDrawing);

                                    DisplayOriginal_GS displayGS = new DisplayOriginal_GS(
                                        lobby: lobby,
                                        displayTimeDuration: MimicConstants.MemorizeTimerLength,
                                        displayDrawing: originalDrawing);
                                    CreateMimics_GS mimicsGS = new CreateMimics_GS(
                                        lobby: lobby,
                                        roundTracker: drawingsRoundTracker,
                                        drawingTimeDuration: extendedDrawingTimer
                                        );
                                    mimicsGS.AddExitListener(() =>
                                    {
                                        List <User> randomizedUsersToDisplay = new List <User>();
                                        List <User> randomizedKeys = drawingsRoundTracker.UsersToUserDrawings.Keys.OrderBy(_ => Rand.Next()).ToList();
                                        for (int i = 0; i < maxVoteDrawings && i < randomizedKeys.Count; i++)
                                        {
                                            randomizedUsersToDisplay.Add(randomizedKeys[i]);
                                        }
                                        if (!randomizedUsersToDisplay.Contains(drawingsRoundTracker.originalDrawer))
                                        {
                                            randomizedUsersToDisplay.RemoveAt(0);
                                            randomizedUsersToDisplay.Add(drawingsRoundTracker.originalDrawer);
                                        }
                                        randomizedUsersToDisplay = randomizedUsersToDisplay.OrderBy(_ => Rand.Next()).ToList();
                                        drawingsRoundTracker.UsersToDisplay = randomizedUsersToDisplay;
                                    });
                                    return new StateChain(states: new List <State>()
                                    {
                                        displayGS, mimicsGS
                                    }, exit: null);
                                }
                                else if (counter < maxDrawingsBeforeVote * 2)
                                {
                                    return GetVotingAndRevealState(roundTrackers[counter - maxDrawingsBeforeVote], votingTimer);
                                }
                                else
                                {
                                    return null;
                                }
                            }));
                        }
                        return(CreateMultiRoundLoop());
                    }
                    else
                    {
                        if (timeToShowScores)
                        {
                            timeToShowScores = false;
                            return(new ScoreBoardGameState(
                                       lobby: lobby,
                                       title: "Final Scores"));
                        }
                        else
                        {
                            //Ends the chain
                            return(null);
                        }
                    }
                });

                gamePlayLoop.Transition(this.Exit);
                return(gamePlayLoop);
            }

            this.Entrance.Transition(Setup);
            Setup.Transition(CreateGamePlayLoop);
        }
Ejemplo n.º 11
0
 private Action <List <UserDrawing>, IDictionary <User, VoteInfo> > CountVotes(RoundTracker roundTracker)
 {
     return((List <UserDrawing> drawings, IDictionary <User, VoteInfo> votes) =>
     {
         foreach ((User user, VoteInfo vote) in votes)
         {
             User userVotedFor = ((UserDrawing)vote.ObjectsVotedFor[0]).Owner;
             if (userVotedFor == roundTracker.originalDrawer)
             {
                 user.ScoreHolder.AddScore(
                     CommonHelpers.PointsForSpeed(
                         maxPoints: MimicConstants.PointsForCorrectPick(drawings.Count),
                         minPoints: MimicConstants.PointsForCorrectPick(drawings.Count) / 10,
                         startTime: MimicConstants.BlurDelay,
                         endTime: MimicConstants.BlurDelay + MimicConstants.BlurLength,
                         secondsTaken: vote.TimeTakenInMs / 1000.0f),
                     Score.Reason.CorrectAnswerSpeed);
             }
             else
             {
                 userVotedFor.ScoreHolder.AddScore(MimicConstants.PointsForVote, Score.Reason.ReceivedVotes);
             }
         }
     });
 }
        public BattleReadyGameMode(Lobby lobby, List <ConfigureLobbyRequest.GameModeOptionRequest> gameModeOptions, StandardGameModeOptions standardOptions)
        {
            GameDuration duration = standardOptions.GameDuration;

            this.Lobby = lobby;
            int numRounds  = BattleReadyConstants.NumRounds[duration];
            int numPlayers = lobby.GetAllUsers().Count();

            TimeSpan?setupDrawingTimer = null;
            TimeSpan?setupPromptTimer  = null;
            TimeSpan?creationTimer     = null;
            TimeSpan?votingTimer       = null;

            int numOfEachPartInHand = (int)gameModeOptions[(int)GameModeOptionsEnum.NumEachPartInHand].ValueParsed;

            int numPromptsPerRound  = Math.Min(numPlayers, BattleReadyConstants.MaxNumSubRounds[duration]);
            int minDrawingsRequired = numOfEachPartInHand * 3; // the amount to make one playerHand to give everyone

            int expectedPromptsPerUser  = (int)Math.Ceiling(1.0 * numPromptsPerRound * numRounds / lobby.GetAllUsers().Count);
            int expectedDrawingsPerUser = Math.Max((minDrawingsRequired / numPlayers + 1) * 2, BattleReadyConstants.NumDrawingsPerPlayer[duration]);

            if (standardOptions.TimerEnabled)
            {
                setupDrawingTimer = BattleReadyConstants.SetupPerDrawingTimer[duration];
                setupPromptTimer  = BattleReadyConstants.SetupPerPromptTimer[duration];
                creationTimer     = BattleReadyConstants.PerCreationTimer[duration];
                votingTimer       = BattleReadyConstants.VotingTimer[duration];
            }

            SetupDrawings_GS setupDrawing = new SetupDrawings_GS(
                lobby: lobby,
                drawings: this.Drawings,
                numExpectedPerUser: expectedDrawingsPerUser,
                setupDurration: setupDrawingTimer * expectedDrawingsPerUser);

            SetupPrompts_GS setupPrompt = new SetupPrompts_GS(
                lobby: lobby,
                prompts: Prompts,
                numExpectedPerUser: expectedPromptsPerUser,
                setupDuration: setupPromptTimer);

            List <Prompt> battlePrompts = new List <Prompt>();
            IReadOnlyList <PeopleUserDrawing> headDrawings = new List <PeopleUserDrawing>();
            IReadOnlyList <PeopleUserDrawing> bodyDrawings = new List <PeopleUserDrawing>();
            IReadOnlyList <PeopleUserDrawing> legsDrawings = new List <PeopleUserDrawing>();

            setupDrawing.AddExitListener(() =>
            {
                // Trim extra prompts/drawings.
                headDrawings = Drawings.ToList().FindAll((drawing) => drawing.Type == BodyPartType.Head);
                bodyDrawings = Drawings.ToList().FindAll((drawing) => drawing.Type == BodyPartType.Body);
                legsDrawings = Drawings.ToList().FindAll((drawing) => drawing.Type == BodyPartType.Legs);
            });
            int numPromptsPerUserPerRound = 0; // Set during below exit listener.

            setupPrompt.AddExitListener(() =>
            {
                battlePrompts      = MemberHelpers <Prompt> .Select_Ordered(Prompts.OrderBy(prompt => prompt.CreationTime).ToList(), numPromptsPerRound * numRounds);
                numRounds          = (battlePrompts.Count - 1) / numPromptsPerRound + 1;
                numPromptsPerRound = (int)Math.Ceiling(1.0 * battlePrompts.Count / numRounds);

                numPromptsPerUserPerRound = Math.Max(1, numPromptsPerRound / 2);
                int maxNumUsersPerPrompt  = Math.Min(12, (int)Math.Ceiling(1.0 * numPlayers * numPromptsPerUserPerRound / numPromptsPerRound));

                foreach (Prompt prompt in battlePrompts)
                {
                    prompt.MaxMemberCount = maxNumUsersPerPrompt;
                }
            });

            List <GameState> creationGameStates     = new List <GameState>();
            List <GameState> votingGameStates       = new List <GameState>();
            List <GameState> voteRevealedGameStates = new List <GameState>();
            List <GameState> scoreboardGameStates   = new List <GameState>();

            int countRounds = 0;

            #region GameState Generators
            GameState CreateContestantCreationGamestate()
            {
                RoundTracker.ResetRoundVariables();
                List <Prompt> prompts = battlePrompts.Take(numPromptsPerRound).ToList();

                battlePrompts.RemoveRange(0, prompts.Count);

                List <IGroup <User> > assignments = MemberHelpers <User> .Assign(
                    prompts.Cast <IConstraints <User> >().ToList(),
                    lobby.GetAllUsers().ToList(),
                    duplicateMembers : (int)Math.Ceiling((1.0 * prompts.Count / numPromptsPerRound) * numPromptsPerUserPerRound));

                var pairings = prompts.Zip(assignments);

                foreach ((Prompt prompt, IGroup <User> users) in pairings)
                {
                    foreach (User user in users.Members)
                    {
                        prompt.UsersToUserHands.TryAdd(user, new Prompt.UserHand
                        {
                            // Users have even probabilities regardless of how many drawings they submitted.
                            HeadChoices = MemberHelpers <PeopleUserDrawing> .Select_DynamicWeightedRandom(headDrawings, numOfEachPartInHand),
                            BodyChoices = MemberHelpers <PeopleUserDrawing> .Select_DynamicWeightedRandom(bodyDrawings, numOfEachPartInHand),
                            LegChoices  = MemberHelpers <PeopleUserDrawing> .Select_DynamicWeightedRandom(legsDrawings, numOfEachPartInHand),
                            Owner       = user
                        });

                        if (!RoundTracker.UsersToAssignedPrompts.ContainsKey(user))
                        {
                            RoundTracker.UsersToAssignedPrompts.Add(user, new List <Prompt>());
                        }
                        RoundTracker.UsersToAssignedPrompts[user].Add(prompt);
                    }
                }

                GameState toReturn = new ContestantCreation_GS(
                    lobby: lobby,
                    roundTracker: RoundTracker,
                    creationDuration: creationTimer);

                toReturn.Transition(CreateVotingGameStates(prompts));
                return(toReturn);
            }

            Func <StateChain> CreateVotingGameStates(List <Prompt> roundPrompts)
            {
                return(() =>
                {
                    StateChain voting = new StateChain(
                        stateGenerator: (int counter) =>
                    {
                        if (counter < roundPrompts.Count)
                        {
                            Prompt roundPrompt = roundPrompts[counter];

                            return GetVotingAndRevealState(roundPrompt, votingTimer);
                        }
                        else
                        {
                            // Stops the chain.
                            return null;
                        }
                    });
                    voting.Transition(CreateScoreGameState(roundPrompts));
                    return voting;
                });
            }

            Func <GameState> CreateScoreGameState(List <Prompt> roundPrompts)
            {
                return(() =>
                {
                    List <Person> winnersPeople = roundPrompts.Select((prompt) => (Person)prompt.UsersToUserHands[prompt.Winner]).ToList();

                    countRounds++;
                    GameState displayPeople = new DisplayPeople_GS(
                        lobby: lobby,
                        title: "Here are your winners",
                        peopleList: winnersPeople,
                        imageTitle: (person) => roundPrompts[winnersPeople.IndexOf(person)].Text,
                        imageHeader: (person) => person.Name
                        );

                    if (battlePrompts.Count <= 0)
                    {
                        GameState finalScoreBoard = new ScoreBoardGameState(
                            lobby: lobby,
                            title: "Final Scores");
                        displayPeople.Transition(finalScoreBoard);
                        finalScoreBoard.Transition(this.Exit);
                    }
                    else
                    {
                        GameState scoreBoard = new ScoreBoardGameState(
                            lobby: lobby);
                        displayPeople.Transition(scoreBoard);
                        scoreBoard.Transition(CreateContestantCreationGamestate);
                    }
                    return displayPeople;
                });
            }

            #endregion

            this.Entrance.Transition(setupDrawing);
            setupDrawing.Transition(setupPrompt);
            setupPrompt.Transition(CreateContestantCreationGamestate);
        }