-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
temp
authored and
temp
committed
May 12, 2012
1 parent
34ad179
commit af5d162
Showing
4 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
var _debug = function( obj ) { | ||
window.console && console.log( obj ); | ||
}; | ||
|
||
var CodeGenerator = function( options ) { | ||
|
||
var options = { | ||
tags : options.tags || null, | ||
score : options.score || 10 | ||
} | ||
|
||
return { | ||
|
||
tags : options.tags, | ||
|
||
score : options.score, | ||
collection : [], | ||
rollers : 3, | ||
|
||
roll : function( number ) { | ||
this.makeCollection( number ); | ||
this.setScore(); | ||
_debug( this.collection ); | ||
}, | ||
|
||
makeCollection : function( number ) { | ||
this.collection = []; | ||
var number = ++number * this.rollers; | ||
while( --number ) { | ||
var item = this.randomize(); | ||
this.collection.push( item ); | ||
} | ||
}, | ||
|
||
check : function() { | ||
|
||
}, | ||
|
||
reset : function() { | ||
this.collection = []; | ||
this.score = options.score; | ||
}, | ||
|
||
randomize : function() { | ||
return this.tags[Math.floor(this.tags.length * Math.random())] | ||
}, | ||
|
||
setScore : function( ) { | ||
|
||
var total = 0; | ||
|
||
var keys = []; | ||
|
||
// Dirty dirty hack | ||
for( var i in this.collection[8] ) { | ||
keys.push( i ); | ||
total += this.collection[8][i]; | ||
_debug( i ); | ||
}; | ||
|
||
for( var i in this.collection[18] ) { | ||
keys.push( i ); | ||
total += this.collection[18][i]; | ||
_debug( i ); | ||
}; | ||
|
||
for( var i in this.collection[28] ) { | ||
keys.push( i ); | ||
total += this.collection[28][i]; | ||
_debug( i ); | ||
}; | ||
// end dirty hack, have a cry, try to forget it! | ||
|
||
|
||
if( total == 3 ) { | ||
this.score++; | ||
|
||
// if we have all the same then extra point!! | ||
if( ( keys[0] == keys[1] ) && ( keys[1] == keys[2] ) ) { | ||
this.score += 2; | ||
} | ||
|
||
} else { | ||
this.score--; | ||
} | ||
|
||
return this.score; | ||
|
||
} | ||
|
||
}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"h2": 1},{"br": 1},{"head": 1},{"body": 1},{"html": 1},{"footer": 1},{"header": 1},{"section": 1},{"img": 1},{"li": 1},{"ul": 1},{"ol": 1},{"menu": 1},{"div": 1},{"nav": 1},{"p": 1},{"q": 1},{"section": 1},{"script": 1},{"span": 1},{"table": 1},{"b": 1},{"h1": 1},{"h2.5": 0},{"foot": 0},{"fr": 0},{"weak": 0},{"z": 0},{"picture": 0},{"part": 0},{"division": 0},{"line": 0},{"page": 0},{"music": 0}] | ||
var codeGeneratorTags = [{"h2": 1},{"br": 1},{"head": 1},{"body": 1},{"html": 1},{"footer": 1},{"header": 1},{"section": 1},{"img": 1},{"li": 1},{"ul": 1},{"ol": 1},{"menu": 1},{"div": 1},{"nav": 1},{"p": 1},{"q": 1},{"section": 1},{"script": 1},{"span": 1},{"table": 1},{"b": 1},{"h1": 1},{"h2.5": 0},{"foot": 0},{"fr": 0},{"weak": 0},{"z": 0},{"picture": 0},{"part": 0},{"division": 0},{"line": 0},{"page": 0},{"music": 0}]; |