Skip to content

Commit

Permalink
Merge 37252de into 7fa61a2
Browse files Browse the repository at this point in the history
  • Loading branch information
iidrees committed Apr 23, 2018
2 parents 7fa61a2 + 37252de commit d461386
Show file tree
Hide file tree
Showing 20 changed files with 474 additions and 301 deletions.
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/andela/nazgul-cfh.svg?branch=develop)](https://travis-ci.org/andela/nazgul-cfh)
[![Coverage Status](https://coveralls.io/repos/github/andela/nazgul-cfh/badge.svg?branch=chore%2F156100320%2Fintegrate-coveralls)](https://coveralls.io/github/andela/nazgul-cfh?branch=develop)
[![Coverage Status](https://coveralls.io/repos/github/andela/nazgul-cfh/badge.svg?branch=develop)](https://coveralls.io/github/andela/nazgul-cfh?branch=develop)

# Cards for Humanity - [http://cfh.io](http://cfh.io)

Cards for Humanity is a fast-paced online version of the popular card game, Cards Against Humanity, that gives you the opportunity to donate to children in need - all while remaining as despicable and awkward as you naturally are.
Expand Down
46 changes: 46 additions & 0 deletions app/controllers/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import mongoose from 'mongoose';

const GameHistory = mongoose.model('GameHistory');

/* Save Game History */

/**
* @class Game
*/
class Game {
/**
* @static
* @param {any} req JSON request
* @param {any} res JSON response
* @returns {any} any
* @memberof Game
*/
static gameHistory(req, res) {
const { gameLog } = req.body;

if (!gameLog) {
return res.status(422).send({
errors: 'No data supplied'
});
}
const GameLog = new GameHistory({
gameID: gameLog.gameId,
gamePlayers: gameLog.players,
gameRound: gameLog.rounds,
gameWinner: gameLog.gameWinner.username
});

GameLog.save((err) => {
if (err) {
return res.status(422).send({
errors: err.errors
});
}
return res.status(201).send({
message: 'Game history successfully saved'
});
});
}
}

export default Game;
21 changes: 21 additions & 0 deletions app/models/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import mongoose from 'mongoose';

const { Schema } = mongoose;

/**
* Game Schema
*/
const gameSchema = new Schema(
{
gameID: String,
gamePlayers: [],
gameRound: Number,
gameWinner: {
type: String,
default: ''
}
},
{ timestamps: true }
);

mongoose.model('GameHistory', gameSchema);
5 changes: 0 additions & 5 deletions app/views/includes/foot.jade
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ script.
g.src = '//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s)
}(document, 'script'));





script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js')
script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js')
script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js')
Expand Down
7 changes: 7 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Game from '../app/controllers/game';

const users = require('../app/controllers/users');
const answers = require('../app/controllers/answers');
const questions = require('../app/controllers/questions');
const avatars = require('../app/controllers/avatars');
const index = require('../app/controllers/index');



module.exports = (app, passport) => {
// User Routes
app.get('/signin', users.signin);
Expand Down Expand Up @@ -92,4 +96,7 @@ module.exports = (app, passport) => {
// Home route
app.get('/play', index.play);
app.get('/', index.render);

// Game history route
app.post('/api/games/:id/start', Game.gameHistory);
};
2 changes: 1 addition & 1 deletion config/socket/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,4 @@ Game.prototype.killGame = function() {
clearTimeout(this.judgingTimeout);
};

module.exports = Game;
module.exports = Game;
2 changes: 1 addition & 1 deletion config/socket/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = function(io) {
// Also checking the number of players, so node doesn't crash when
// no one is in this custom room.
if (game.state === 'awaiting players' && (!game.players.length ||
game.players[0].socket.id !== socket.id)) {
game.players[0].socket.id !== socket.id) && game.players.length < game.playerMaxLimit) {
// Put player into the requested game
console.log('Allowing player to join',requestedGameId);
allPlayers[socket.id] = true;
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"scripts": {
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"cover:test": "nyc --reporter=lcov --reporter=text-lcov",
"bower": "node node_modules/gulp-cli/bin/gulp install",
"start:dev": "node node_modules/gulp-cli/bin/gulp build && node node_modules/gulp-cli/bin/gulp",
"build": "node node_modules/gulp-cli/bin/gulp build ",
"start": "npm run build && node dist/server.js",
"test": "NODE_ENV=test && node node_modules/gulp-cli/bin/gulp test --exit",
"postinstall": "node node_modules/gulp-cli/bin/gulp install",
"test:karma": "node_modules/.bin/karma start karma.conf.js",
"test:protractor": "protractor ./test/e2e/conf.js"
"test:protractor": "protractor ./test/e2e/conf.js",
"webdriver-manager": "webdriver-manager update"
},
"dependencies": {
"async": "~0.2.9",
Expand Down Expand Up @@ -60,7 +60,6 @@
"passport-google-oauth": "~0.1.5",
"passport-local": "~0.1.6",
"passport-twitter": "~1.0.2",
"protractor": "^5.3.1",
"sinon": "~1.7.3",
"socket.io": "~0.9.16",
"socket.io-client": "~0.9.16",
Expand Down Expand Up @@ -106,7 +105,6 @@
"mocha": "^5.0.5",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^11.6.0",
"protractor": "^5.3.1",
"should": "~1.3.0",
"supertest": "~0.8.0"
}
Expand Down
21 changes: 13 additions & 8 deletions public/js/controllers/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,26 @@ angular.module('mean.system')
$http.defaults.headers.common.Authorization = authToken;

$scope.openSearchModal = () => {
document.getElementById('myModal').style.display = 'block';
$('#myModal').modal('open');
};

$scope.closeSearchModal = () => {
document.getElementById('myModal').style.display = 'none';
$('#myModal').modal('close');
};

$scope.closeCannotStartGameModal = () => {
document.getElementById('cannot-start-game-modal').style.display =
'none';
$('#cannot-start-game-modal').modal('close');
};
$scope.newGameModal = () => {
$('#promptModal').modal('close');
game.startGame();
};
$scope.newGameModal1 = () => {
$('#promptModal').modal('close');
};

$rootScope.$on('maxPlayersReached', () => {
document.getElementById('game-already-started-modal').style.display =
'block';
$('#game-already-started-modal').modal('open');
});

$scope.startTour = () => {
Expand Down Expand Up @@ -283,9 +288,9 @@ angular.module('mean.system')

$scope.startGame = () => {
if (game.players.length < 3) {
document.getElementById('cannot-start-game-modal').style.display = 'block';
$('#cannot-start-game-modal').modal('open');
} else {
game.startGame();
$('#promptModal').modal('open');
}
};

Expand Down
Loading

0 comments on commit d461386

Please sign in to comment.