-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.js
77 lines (61 loc) · 1.7 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Only the js file for declaration
// Read more here : http://docs.meteor.com/#coffeescript
//
//
//
//
//
//
//
//
// Start collections declaration
//
Games = new Meteor.Collection('games');
Players = new Meteor.Collection('players');
Colors = new Meteor.Collection('colors');
// End collections declaration
//
// -------------------------
//
//Start global varibale declaration
//
var q = 0;
// Start functions declaration
//new_board :: generate a new random selection of letters.
new_board = function () {
console.log("GENERATING NEW BOARD!!!!!!!!");
var board = [];
console.log("adding items");
for (var i = 0; i < 20; i++){
var row = [];
for (var j = 0; j < 20; j++){
row.push({i: i,j: j, color: "grey"});
}
board.push(row);
}
return board;
};
//insert_colors :: insert random ten colors in db
insert_colors = function () {
var letters = '0123456789ABCDEF'.split('');
chosen_color = '#';
for (var j = 0; j < 6; j++ ) {
chosen_color += letters[Math.round(Math.random() * 15)];
}
Colors.insert({"cid" : q , color : chosen_color, use:0});
q++;
};
//get_random_color :: get a random element of COLORS array
get_random_color = function() {
var count = Colors.find({ use : 0 }).count();
if(count == 0) {
insert_colors();
count = Colors.find({ use : 0 }).count();
}
var t = parseInt(Math.random()*count,10);
var col = Colors.findOne({"cid" : t});
var chosen_color = col.color;
Colors.update({"_id" : col._id }, { $set : { "use" : 1 } });
console.log(chosen_color);
return chosen_color;
};