make bonfire dynamically direct to best subsequent bonfire after completion

This commit is contained in:
Michael Q Larson
2015-01-24 14:29:50 -08:00
parent 1b75a6a7b8
commit c4bd0e4dc3
4 changed files with 80 additions and 5 deletions

3
app.js
View File

@ -258,8 +258,9 @@ app.get('/account/api', userController.getAccountAngular);
app.get('/bonfire', bonfireController.index);
app.get(
'/bonfires/:bonfireNumber',
bonfireController.returnBonfire
bonfireController.returnIndividualBonfire
);
app.get('/bonfires', bonfireController.returnBonfire);
// Unique Check API route
app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername);

View File

@ -1,6 +1,7 @@
var _ = require('lodash'),
debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire');
Bonfire = require('./../models/Bonfire'),
User = require('./../models/User');
/**
* Bonfire controller
@ -49,9 +50,78 @@ exports.returnBonfire = function(req, res, next) {
"Prove to mom that computers aren't just for games"
];
// This code is in bad need of refactoring
var bonfiresToFind = req.user.bonfiresHash;
var bonfiresArray = _.map(bonfiresToFind, function(value, index) {
return [index, value];
});
// Get rid of the first entry, which will be a useless function that causes an error.
bonfiresArray.shift();
unsolvedBonfires = [];
for (i = 0; i < bonfiresArray.length; i++) {
if (bonfiresArray[i][1]["completedDate"] === 0) {
unsolvedBonfires.push(bonfiresArray[i][0])
}
}
//.where('likes').in(['vaporizing', 'talking'])
var displayedBonfires = Bonfire.find({}).where('_id').in(unsolvedBonfires).sort({ difficulty: 1 });
displayedBonfires.exec(function(err, bonfire) {
if (err) {
next(err);
}
res.render('bonfire/show', {
completedWith: null,
title: bonfire[bonfireNumber].name,
name: bonfire[bonfireNumber].name,
number: bonfire[bonfireNumber].bonfireNumber,
difficulty: bonfire[bonfireNumber].difficulty,
description: bonfire[bonfireNumber].description,
tests: bonfire[bonfireNumber].tests,
challengeSeed: bonfire[bonfireNumber].challengeSeed,
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
cc: req.user ? req.user.bonfiresHash : undefined,
points: req.user ? req.user.points : undefined,
verb: verbs[Math.floor(Math.random() * verbs.length)],
phrase: phrases[Math.floor(Math.random() * phrases.length)],
bonfires: bonfire,
bonfireHash: bonfire[bonfireNumber]._id
});
});
};
exports.returnIndividualBonfire = function(req, res, next) {
var bonfireNumber = parseInt(req.params.bonfireNumber) || 0;
var verbs = [
'ACED',
'NAILED',
'ROCKED',
'SCORCHED',
'DEVASTATED',
'OWNED',
'CRUSHED',
'CONQUERED',
'KILLED',
'SHREDDED',
'ANNIHILATED',
'NUKED'
];
var phrases = [
"Shout it from on top of a mountain",
"Tell everyone and their dogs",
"Show them. Show them all!",
"Inspire your friends",
"Tell the world of your greatness",
"Look accomplished on social media",
"Share news of your grand endeavor",
"Establish your alibi for the past two hours",
"Prove to mom that computers aren't just for games"
];
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
Bonfire.find({}, null, { sort: { difficulty: 1, bonfireNumber: 1 } }, function(err, bonfire) {
debug(bonfire[bonfireNumber].challengeEntryPoint);
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) {
if (err) {
next(err);
}

View File

@ -355,6 +355,7 @@ var userSchema = new mongoose.Schema({
resetPasswordExpires: Date,
bonfiresHash: {
aaa48de84e1ecc7c742e1124: {
hash: String,
completedWith: String,
completedDate: {
type: Number,
@ -363,6 +364,7 @@ var userSchema = new mongoose.Schema({
solution: String
},
ff0395860f5d3034dc0bfc94: {
hash: String,
completedWith: String,
completedDate: {
type: Number,

View File

@ -15,4 +15,6 @@
| &nbsp;
a.ion-information-circled(title="About Free Code Camp", href="/learn-to-code")
| &nbsp;
a.ion-locked(title="Free Code Camp's Privacy Policy", href="/privacy")
a.ion-locked(title="Free Code Camp's Privacy Policy", href="/privacy")
| &nbsp;
a.ion-code-working(title="Bonfire Coding Playground", href="/bonfire")