From 2e1198c7dc778718282c7380e9c8f78f74a109f9 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Sun, 21 Aug 2016 11:31:19 +1000 Subject: [PATCH] *custom thing chance ratios for each level *make llamas only start appearing a few levels in --- cat.html | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++------ todo | 18 ++++++++------ 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/cat.html b/cat.html index b3991f3..2f67dc8 100644 --- a/cat.html +++ b/cat.html @@ -301,14 +301,19 @@ function isvalidpath(mypath) { // would adding 'overthing' to our existing path result in a valid path? function canextendpath(overthing) { + var pathtype; + if (!overthing) return false; + pathtype = getpathtype(); + if ( isadjacent(overthing, curpath[curpath.length-1]) && // adjacent to last thing in path? !pathcontains(overthing) && // path doesn't already contain this? - (getpathtype() == "parade" || isinpathdir(overthing)) // path in a straight line + (pathtype == "parade" || isinpathdir(overthing)) // path in a straight line ) { // create a fake new path containing this. var fakepath = curpath.slice(); + fakepath.push(overthing); if (isvalidpath(fakepath)) { return true; @@ -697,9 +702,20 @@ var game = { mylevel = new Object(); mylevel.hashelp = hashelp; mylevel.goals = new Array(); + mylevel.thinglist = new Array(); this.levels[lev] = mylevel; }, + // thingtype pct + addlevelthings: function (lev) { + var i,idx; + for (i = 1 ; i < arguments.length; i += 2) { + idx = this.levels[lev].thinglist.push(new Object()) - 1; + this.levels[lev].thinglist[idx].type = arguments[i]; + this.levels[lev].thinglist[idx].pct = arguments[i+1]; + } + }, + // goal1type goal1count goal2type goal2count etc... addlevelgoals : function (lev) { var i,idx; @@ -737,9 +753,14 @@ var game = { this.levels = []; this.addlevel(1, true); this.addlevelgoals(1, "food", 10); + this.addlevelthings(1, "cat", 45, "food", 100); this.addlevel(2, false); this.addlevelgoals(2, "points", 200); + this.addlevelthings(1, "cat", 45, "food", 100); + + this.addlevel(3, false); + this.addlevelgoals(3, "points", 500); /* for (i = 1; i < this.levels.length; i++) { @@ -764,6 +785,8 @@ var game = { var i; while (!anyvalidmoves()) { var m; + + console.log("populating grid..."); clearthings(); // populate initial things @@ -1584,14 +1607,50 @@ function shadowtext(ctx, text, size, col, x, y) { } function getrandomtype() { - var pct,type; - pct = Math.random() * 100; - if ( pct < 45) { - type = "cat"; - } else if ( pct < 90) { - type = "food"; + var pct,type = null,i; + var thinglist; + + if (curlevel >= game.levels.length) { + thinglist = null; } else { - type = "llama"; + thinglist = game.levels[curlevel].thinglist; + } + if (thinglist == undefined || thinglist.length == 0) { + // default thinglist + thinglist = [ + { + type: 'cat', + pct: 45 + }, + { + type: 'food', + pct: 90 + }, + { + type: 'llama', + pct: 100 + } + ]; + } + + /* + console.log("thinglist length is " + thinglist.length); + for (i = 0; i < thinglist.length; i++) { + console.log(" thing " + i + " is " + thinglist[i].type + " pct " + thinglist[i].pct); + } + */ + + pct = Math.random() * 100; + for (i = 0; i < thinglist.length; i++) { + if (pct <= thinglist[i].pct) { + type = thinglist[i].type; + break; + } + } + + if (type == null) { + console.log("couldn't find type! pct is " + pct); + type = 'cat'; } return type; } diff --git a/todo b/todo index 2b122a3..497f29a 100644 --- a/todo +++ b/todo @@ -29,18 +29,20 @@ phone fixes as per http://www.html5rocks.com/en/mobile/touch/ https://www.smashingmagazine.com/2012/10/design-your-own-mobile-game/ -custom thing chance ratios for each level - 1: no llamas - 2: no llamas - 3: llamas +*custom thing chance ratios for each level +*make llamas only start appearing a few levels in -make llamas only start appearing a few levels in +restrict catparades on level 1 - + cat can only go to cheese! make help text for llamas come later - llamas scaring cats - parades can have one llama + (keep orig help around for reference) + lv1 help: just how to eat cheese + lv2 help: just how to make cat parades + lv3 help: + llamas scaring cats + parades can have one llama -make initial help text jsut talk about paraes, no llamas Level selection screen