12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- angular.module('tabooServices', [])
- .factory('Taboo', function($rootScope, Chat) {
- var game = {};
- game.startRound = function() {
- Chat.send('/start');
- };
- game.status = function() {
- Chat.send('/status');
- };
- game.roundStart = function() {
- game.pendingRound = false;
- game.startTime = new Date();
- game.points = 0;
- };
- game.roundEnd = function() {
- game.pendingRound = false;
- game.card = null;
- };
- $rootScope.$on('ws:connected', init);
- $rootScope.$on('ws:message', onmessage);
- function init() {
- game.teamA = null;
- game.teamB = null;
- game.card = null;
- game.points = 0;
- game.pendingRound = false;
- game.status();
- }
- function onmessage(event, message) {
- if(message.kind == "point") {
- var text = "";
- if(message.action == "correct") {
- text = message.user + " got it!";
- }
- else if(message.action == "invalid") {
- text = "Uh-uh! You said a taboo word.";
- }
- else if(message.action == "pass") {
- text = "Tsk tsk. You passed.";
- }
- else if(message.action == "taboo") {
- text = "Oh no! "+message.user+" has called you out.";
- }
- text += " The last word was "+message.card.word+".";
- gmMessage(text);
- game.points = message.points;
- }
- else if(message.kind == "roundReady") {
- gmMessage("Next round, the player will be "+message.player);
- if(message.player == Chat.username) {
- game.pendingRound = true;
- }
- }
- else if(message.kind == "roundStart") {
- gmMessage("Start game!");
- game.roundStart();
- }
- else if(message.kind == "roundEnd") {
- if(message.card) {
- gmMessage("Time's up! The last word was "+message.card.word+".");
- }
- gmMessage("The round has ended. The team got "+message.points+".");
- game.roundEnd();
- }
- else if(message.kind == "card") {
- game.card = message.card;
- }
- else if(message.kind == "status" || message.kind == "join" || message.kind == "quit") {
- updateStatus(message);
- }
- }
- function updateStatus(message) {
- game.teamA = message.teamA;
- game.teamB = message.teamB;
- }
- function gmMessage(message) {
- Chat.receive("gm", "*GM", message);
- }
- return game;
- })
|