samurailink3 / hangouts-against-humanity

A game for horrible people, on Google+, in a hangout.
GNU Affero General Public License v3.0
110 stars 35 forks source link

Shuffle Cards for Card Czar #15

Open samurailink3 opened 11 years ago

samurailink3 commented 11 years ago

Currently, cards come in in the order they are submitted. Cards should be shuffled before being presented to the Card Czar.

icbat commented 11 years ago

Here's how I've been looking at this. I'm pretty new to JS, so I'm posting to ask for some help groking the code.


function doReaderTurn() {
...
...
...
        function checkSubmission()
        {
            numLoops++;
            //all submission in or 3 minutes passed (in case of a drop)
            Ext.getCmp('gameStatePanel').setTitle("Round Timer:" + (120-numLoops) + " seconds");
            if (numSubmissions == numPlayers-1 || numLoops > 120) {
                clearInterval(sLoop);
                Ext.getCmp('gameStatePanel').setTitle("Game State");

                // New bit
                shuffleAnswers(); 

                revealCards();
            }
        }
    }
}

with that new function looking something like:


function shuffleAnswers()
{
    $(.'answerContainer').sort(function () 
    {
        return 0.5 - Math.random()
    }; //Unsure how to make this nested anonymous fn match your bracket style
}

It obviously doesn't have to be its own function (but maybe should be for readability). I don't really grasp how the $('.xxxx') syntax works, whether that can be mutated or not. If it can't, I suppose the other possibility is to modify revealCards to save a cache it as a var first, then shuffle, then show.

Thoughts? I'm sorry to write with such ignorance, but hopefully I'm on a right-ish track.

magic-madrigal commented 11 years ago

I'm going to be playing a game in my test environment tonight. I will add your code, and let you know what I find.

-Ed

joshuha commented 11 years ago

So the $() selector syntax is just jQuery selectors. A personal preference but you can use the normal JS selectors fine still. The issue I have been coming up with in a randomizer function is it is easy enough to do for the Czar but synching it with the client seems to be a pain. It only matter most for the Czar but might still be odd that the Czar is clicking say his left one but it's really the middle one on everyone else's screen. We could just have everyone randomize order on every screen and it wouldn't be huge deal as long as the right card got revealed.

samurailink3 commented 11 years ago

I think randomizing the order for everyone (even un-synced) is a decent idea.

tresi commented 11 years ago

Unrandomized cards when the czar is reading/selecting is the number 1 complaint from the group I play with.

samurailink3 commented 11 years ago

@joshuha is planning on this being included in the v2 rewrite.