From de1eda15955f5d6ee311475355b886214d43f53c Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 19 Apr 2020 12:48:46 -0500 Subject: Add prompt and add waiting for list --- src/quiz-bunny/index.html | 38 +++++++++++++++++++--- src/quiz-bunny/prompts.js | 55 +++++++++++++++++++++++++++++++ src/quiz-bunny/server.js | 70 +++++++++++++++++++++++++++++++++------- src/quiz-bunny/static/main.js | 3 ++ src/quiz-bunny/static/styles.css | 1 + 5 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 src/quiz-bunny/prompts.js (limited to 'src/quiz-bunny') diff --git a/src/quiz-bunny/index.html b/src/quiz-bunny/index.html index eadba94..127db65 100644 --- a/src/quiz-bunny/index.html +++ b/src/quiz-bunny/index.html @@ -27,7 +27,8 @@ :disabled="username.length == 0">
- +
@@ -39,7 +40,7 @@

{{game.gameCode}}

Players

@@ -49,15 +50,33 @@

Answer:

{{game.prompt}}

- + +
+

Waiting:

+
    +
  • + {{player.name}} +
  • +
+

Vote:

{{game.prompt}}

- + +
+
+

Waiting:

+
    +
  • + {{player.name}} +
  • +
@@ -67,11 +86,20 @@ {{answer.text}}{{answer.voteCount}} votes
+
+

Waiting:

+
    +
  • + {{player.name}} +
  • +
+

Scores:

    -
  1. {{score.name}}{{score.score}}
  2. +
  3. {{score.name}}{{score.score}} +
diff --git a/src/quiz-bunny/prompts.js b/src/quiz-bunny/prompts.js new file mode 100644 index 0000000..c6326cd --- /dev/null +++ b/src/quiz-bunny/prompts.js @@ -0,0 +1,55 @@ +var prompts = [ + "@ reminds you most of what animal?", + "If @ was a movie genre, what would they be?", + "If @ was a breakfast cereal, what would they be?", + "What would a documentary about @ be titled?", + "If @ and @ formed a band, what would it be called?", + "Describe @'s dream house", + "What will it say on @'s tombstone", + "If @ sued @, what would be the reason", + "What would be the name of @'s podcast", + "@ starts a store, selling what?", + "What is @ hiding in their browser history?", + "What was the last video @ watched?", + "What does @ do to get rid of stress?", + "What is something @ is obssessed with?", + "What three words best describe @?", + "What is the most useful thing @ owns?", + "What popular thing annoys @?", + "If @ had intro music, what would it be?", + "If @ taught a class, what would it be in?", + "If @ had to spend the weekend at @'s house, what would they do?", + "If @ got @ a gift, what would it be?", + "What do @ and @ have in common?", + "What would @ wear to a fashion show?", + "What is @'s go to curse word?", + "What is @'s catchphrase?", + "What does @ say to @ most frequently?", + "What is on @'s bucket list", + "What will @ never do?", + "What is @'s favorite TV show?", + "If @ was the host of a reality TV show, what would it be about?", + "What is the last song @ listened to?", + "What is @'s go to restaurant owner?", + "What would @ cook for a dinner party?", + "What is the coolest thing @ has done?", + "What is at the top of @'s grocery list?", + "If @ and @ were in a movie together, what would the title be?", + "@ and @ are cast in a movie remake, what movie would it be?", + "What game has @ played the most", + "If @ wrote the next ten commandments, what would the first one be?", + "What did @ last search for online?", + "If @ had children, what will their parenting catchphrase be?", + "In a movie about @, who would be the lead?", + "What would happen to @ during the apocalypse?", + "What is @'s ideal vacation?", + "What movie quote best describes @", + "If @ changed their profession to an area they haven't shown interest in, what would it be?", + "What smell is @'s favorite?", + "What conspiracy theory is @ most likely to believe in?", + "Which national park would @ like to visit most?", + "If @ had a different first name, what would it be?", +] +module.exports = { + prompts +} \ No newline at end of file diff --git a/src/quiz-bunny/server.js b/src/quiz-bunny/server.js index 12a0090..3a36baf 100644 --- a/src/quiz-bunny/server.js +++ b/src/quiz-bunny/server.js @@ -1,5 +1,6 @@ const uuidv4 = require('uuid/v4'); const words = require('./words').words; +const prompts = require('./prompts').prompts; function setUpRoutes(server, models, jwtFunctions, database) { // simple send files @@ -15,9 +16,6 @@ function setUpRoutes(server, models, jwtFunctions, database) { OVER: 2, WAITING: 3, } - setInterval(function(){ - console.log(games) - }, 3000) // generates a game code function generateGameCode() { @@ -54,7 +52,10 @@ function setUpRoutes(server, models, jwtFunctions, database) { return game.players.find(player => player.cookie == cookie) } function getPlayerNames(players) { - return players.map(player => player.name) + // return players.map(player => player.name) + return players.map(player => { + return {name: player.name, ready: player.ready} + }) } // Turn the game into a public game object (no cookies, etc.) function getPublicGame(cookie) { @@ -65,6 +66,7 @@ function setUpRoutes(server, models, jwtFunctions, database) { let isHost = cookie == game.host let username = game.players.find(player => player.cookie == cookie).name let players = getPlayerNames(game.players) + // console.log(players) var newGame = { host: isHost, players: players, @@ -76,12 +78,28 @@ function setUpRoutes(server, models, jwtFunctions, database) { if (game.state == STATES.TYPING) { newGame.submitted = game.answers.some(answer => answer.cookie == cookie) newGame.prompt = game.prompts[game.round] + newGame.players.forEach(player => { + var playerWithCookie = game.players.find(p => { + return p.name == player.name + }) + if(game.answers.some(answer => answer.cookie == playerWithCookie.cookie)){ + player.ready = true + } else { + player.ready = false + } + }) } else if (game.state == STATES.VOTING) { newGame.answers = game.answers.map(answer => answer.text) newGame.prompt = game.prompts[game.round] var game = findGameByCookie(cookie) var player = findPlayerByCookie(game, cookie) newGame.voted = player.voted + newGame.players.forEach(player => { + var playerWithCookie = game.players.find(p => { + return p.name == player.name + }) + player.ready = playerWithCookie.voted + }) } else if (game.state == STATES.WAITING) { newGame.answers = game.answers.map(answer => { return { text: answer.text, voteCount: answer.votes.length } @@ -102,17 +120,46 @@ function setUpRoutes(server, models, jwtFunctions, database) { return newGame } } + function shuffle(a) { + var j, x, i; + for (i = a.length - 1; i > 0; i--) { + j = Math.floor(Math.random() * (i + 1)); + x = a[i]; + a[i] = a[j]; + a[j] = x; + } + return a; + } + function getRandomPlayer(stack, playersList){ + if(stack.length == 0){ + for(var i = 0; i < playersList.length; i++){ + stack.push(playersList[i]) + } + shuffle(stack) + } + return stack.shift() + } // gets a game prompt - function getPrompts(players) { - // temporary hard coded 2 rounds - return [`What would ${players[0]} eat for breakfast?`, `What would ${players[1]} be famous for?`] + function getPrompts(playerNames, size) { + var gamePrompts = [] + var stack = [] + for(var i = 0; i < size; i++){ + var randomIndex = Math.floor(Math.random() * prompts.length) + var prompt = prompts[randomIndex] + while(prompt.includes("@")){ + prompt = prompt.replace("@", getRandomPlayer(stack, playerNames)) + } + gamePrompts.push(prompt) + } + return gamePrompts } // marks the game as started function startGame(cookie) { let game = games.find(el => el.host == cookie) - if (game) { + if (game && game.players.length >= 2) { game.gameStarted = true - game.prompts = getPrompts(getPlayerNames(game.players)) + var playerNames = game.players.map(player => player.name) + game.prompts = getPrompts(playerNames, 8) game.round = 0; game.players.forEach(player => { player.score = 0 @@ -174,11 +221,12 @@ function setUpRoutes(server, models, jwtFunctions, database) { function voteFor(cookie, answerIndex) { let game = findGameByCookie(cookie) let playerWhoVoted = findPlayerByCookie(game, cookie) - if (playerWhoVoted.voted) { + let answer = game.answers[answerIndex] + // If already voted, or voted for self, ignore + if (playerWhoVoted.voted || answer.cookie == cookie) { return false } playerWhoVoted.voted = true - let answer = game.answers[answerIndex] answer.votes.push(playerWhoVoted) game.voteCount++ if (game.voteCount == game.players.length) { diff --git a/src/quiz-bunny/static/main.js b/src/quiz-bunny/static/main.js index cb4740e..a7309bb 100644 --- a/src/quiz-bunny/static/main.js +++ b/src/quiz-bunny/static/main.js @@ -15,6 +15,9 @@ window.onload = function () { interval: undefined }, methods: { + nonReady: function (players) { + return players.filter(player => !player.ready) + }, startStatusLoop: function(){ // event loop that runs while waiting for host to start var loadStatus = function (vue_object) { diff --git a/src/quiz-bunny/static/styles.css b/src/quiz-bunny/static/styles.css index 9734c87..e128102 100644 --- a/src/quiz-bunny/static/styles.css +++ b/src/quiz-bunny/static/styles.css @@ -17,6 +17,7 @@ input[type=button]{ cursor: pointer; background-color: coral; color: white; + white-space: normal; } input[type=button]:disabled { color: #eeeeee; -- cgit v1.2.3