Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/Know-USA/js/lesson.js
blob: 029b5aa0e6cae4c69e0ca6c58d29c9a060612221 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
$(document).ready(function(){

	//Program constants
	var SVG_MAP = document.getElementById('mysvg');
    // disable scrolling
    document.body.style.overflow = 'hidden';

	//Game Control
	var isActive = true;
	var question = [];
	var answeredCorrect = false;


    var colors = [
    "aliceblue",
    "antiquewhite",
    "aqua",
    "aquamarine",
    "azure",
    "beige",
    "bisque",
    "black",
    "blanchedalmond",
    "blue",
    "blueviolet",
    "brown",
    "burlywood",
    "cadetblue",
    "chartreuse",
    "chocolate",
    "coral",
    "cornflowerblue",
    "cornsilk",
    "crimson",
    "cyan",
    "darkblue",
    "darkcyan",
    "darkgoldenrod",
    "darkgray",
    "darkgreen",
    "darkgrey",
    "darkkhaki",
    "darkmagenta",
    "darkolivegreen",
    "darkorange",
    "darkorchid",
    "darkred",
    "darksalmon",
    "darkseagreen",
    "darkslateblue",
    "darkslategray",
    "darkslategrey",
    "darkturquoise",
    "darkviolet",
    "deeppink",
    "deepskyblue",
    "dimgray",
    "dimgrey",
    "dodgerblue",
    "firebrick",
    "floralwhite",
    "forestgreen",
    "fuchsia",
    "gainsboro",
    "ghostwhite",
    "gold",
    "goldenrod",
    "gray",
    "grey",
    "green",
    "greenyellow",
    "honeydew",
    "hotpink",
    "indianred",
    "indigo",
    "ivory",
    "khaki",
    "lavender",
    "lavenderblush",
    "lawngreen",
    "lemonchiffon",
    "lightblue",
    "lightcoral",
    "lightcyan",
    "lightgoldenrodyellow",
    "lightgray",
    "lightgreen",
    "lightgrey",
    "lightpink",
    "lightsalmon",
    "lightseagreen",
    "lightskyblue",
    "lightslategray",
    "lightslategrey",
    "lightsteelblue",
    "lightyellow",
    "lime",
    "limegreen",
    "linen",
    "magenta",
    "maroon",
    "mediumaquamarine",
    "mediumblue",
    "mediumorchid",
    "mediumpurple",
    "mediumseagreen",
    "mediumslateblue",
    "mediumspringgreen",
    "mediumturquoise",
    "mediumvioletred",
    "midnightblue",
    "mintcream",
    "mistyrose",
    "moccasin",
    "navajowhite",
    "navy",
    "oldlace",
    "olive",
    "olivedrab",
    "orange",
    "orangered",
    "orchid",
    "palegoldenrod",
    "palegreen",
    "paleturquoise",
    "palevioletred",
    "papayawhip",
    "peachpuff",
    "peru",
    "pink",
    "plum",
    "powderblue",
    "purple",
    "red",
    "rosybrown",
    "royalblue",
    "saddlebrown",
    "salmon",
    "sandybrown",
    "seagreen",
    "seashell",
    "sienna",
    "silver",
    "skyblue",
    "slateblue",
    "slategray",
    "slategrey",
    "snow",
    "springgreen",
    "steelblue",
    "tan",
    "teal",
    "thistle",
    "tomato",
    "turquoise",
    "violet",
    "wheat",
    "white",
    "whitesmoke",
    "yellow",
    "yellowgreen",
    ];

/*
 *  this is just a simpler color list than the one above
    var colors = [
     "pink", "red", "orange", "brown", "yellow", "green", "cyan",
     "blue", "violet",
    ];
    */
    var randomColor = function()
    {
        return colors[Math.floor(Math.random() * colors.length)];
    }

	// You can't access any properties of the svg document 
	// until it has loaded
	$('#mysvg').bind('load', function() {
	    var svgMapDoc = SVG_MAP.getSVGDocument();

        var STATES = $(svgMapDoc).find('.state');

        var getState = function(name) {  // returns the svg group element matching the given state
            return STATES.filter(function() { return $(this).attr('id') === name });
        }
        var names = $.map(STATES, function(i) { return $(i).attr('id'); });
        var questions = names;

	    var hideAnswers = function (svgRoot) {
            $('.text', svgRoot).attr('display', 'none');
	    };

        svgMapDoc.documentElement.currentScale = 0.9;

	    hideAnswers(svgMapDoc);

	    //gameplay functions
	    var changeQuestion = function (questions){
            var index = Math.round(Math.random() * (questions.length - 1));
            var question = questions[index];
            
            //drop the question used from the list of questions
            if (index === 0 ){
                questions.shift();
            } else {
                questions.splice(index, 1)
            }
            
            return question;
	    };

        // questions
	    var askQuestion = function (questions) {

            question = changeQuestion(questions);		

            if (question) {
                $('#question').text("Where is " + question + "?");
            } else {
                $('#question').text("Congratulations!  You have found every state!");
            }

	    };

        STATES.click(function (event) {
            $this = $(this);
            if(isActive){
                if ( question.toLowerCase() === $this.attr('id').toLowerCase()){
                    var color = randomColor();
                    colors.splice(colors.indexOf(color), 1); // remove the color
                    $this.animate({svgFill: color}, 1000);
                    $('#answer').text("Correct! You found " + question + ".");
                    $('.text.' + question.dept, svgMapDoc).attr('display', '');
                    var timerID = setTimeout(function() {
                        $('#answer').text('');
                        askQuestion(questions);
                    }, 3000);
                } else {
                    $('#answer').text("Incorrect. Please try again.");
                }
            } else {
                // do nothing if game is not active
            }
        });
	    
	    askQuestion(questions);

	    
	    

	});

});