"use strict";

var games = [
	"alarm",
	"bacon",
	"brush-teeth",
	"clean-ear",
	"crack-eggs",
	"feed-cat",
	"make-bed",
	"slippers"
];

function randomItem(array) {
	var i = Math.floor(Math.random() * array.length);
	return array[i];
}

module.exports = function(entity, game) { // eslint-disable-line no-unused-vars
	var failure = game.entities.find("failure").length > 0;
	console.log(failure ? "failure" : "success");
	var scene = randomItem(games);
	console.log(scene);
	console.log(game);
	var lives = game.arguments.lives;
	if (lives === undefined) {
		lives = 4;
	}
	console.log(lives, "lives (next scene)");
	if (failure) {
		lives--;
	}
	if (lives === 0) {
		game.switchScene("main");
	} else {
		game.switchScene(scene, { "lives": lives });
	}
};

@@ -133,104 +133,317 @@
 %5D;%0A%0A
-function randomItem(array) %7B%0A%09var i = Math.floor(Math.random() * array.length);%0A%09return array%5Bi%5D
+var currentGames = %5B%5D;%0A%0Afunction shuffle(o) %7B%0A%09for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o%5B--i%5D, o%5Bi%5D = o%5Bj%5D, o%5Bj%5D = x);%0A%09return o;%0A%7D%0A%0Afunction getNextGame() %7B%0A%09if (currentGames.length === 0) %7B%0A%09%09currentGames = games.slice();%0A%09%09shuffle(currentGames);%0A%09%7D%0A%09return currentGames.pop()
 ;%0A%7D%0A
@@ -644,24 +644,20 @@
 e = 
-randomItem(games
+getNextGame(
 );%0A%09
@@ -680,28 +680,8 @@
 e);%0A
-%09console.log(game);%0A
 %09var
@@ -756,54 +756,11 @@
  4;%0A
+
 %09%7D%0A
-%09console.log(lives, %22lives (next scene)%22);%0A
 %09if 

add random levels