forked from github/game-off-2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1732 lines (1390 loc) · 81.3 KB
/
index.html
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE>
<html>
<head>
<title>Git Master</title>
<link href="application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
<link href="ui-lightness/jquery-ui-1.8.23.custom.css" media="screen" rel="stylesheet" type="text/css" />
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> -->
<script type="text/javascript">
window.onload = function () {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext("2d");
// Dot Coordinate System
//
// Row
// 2|
// 1|
// 0|_________
// 0 1 2 3
// Columns
////////////////////////////////////////////////////////////////////////////
//////// BEGIN CONSTANTS AND GLOBAL VARIABLES
BOTTOM_LEFT_X = 60;
BOTTOM_LEFT_Y = 600;
SPACING = 60;
DOT_RADIUS = 13;
currently_clicked = null;
secondary_clicked = null;
tertiary_clicked = null;
current_level = null;
current_dots = null;
removed_dots = [];
current_master_branch = null;
all_branches = null;
move_in_progress = null;
all_levels = [];
placed_dots = [];
level_maker_on = false;
currently_selected_palette_dot = null;
new_level_starting_positions_string = "";
new_level_solution_dots_string = "";
new_level_starting_positions_string_array = "";
new_level_solution_dots_string_array = "";
new_level_num_placed = 0;
//////// END CONSTANTS AND GLOBAL VARIABLES
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//////// BEGIN DOTS
function Dot(color, r, y_row_position, x_column_position, parent_dot, clickable) {
var bottom_left_x = BOTTOM_LEFT_X;
if (typeof clickable != 'undefined' && clickable === true) {
bottom_left_x = BOTTOM_LEFT_X + 75;
}
else {
clickable = false;
}
this.fillStyle = color;
this.positionX = bottom_left_x + (x_column_position*SPACING);
this.positionY = BOTTOM_LEFT_Y - (y_row_position*SPACING);
this.radius = r;
this.sAngle = 0;
this.eAngle = 2 * Math.PI;
this.clockwise = false;
this.y_row_position = y_row_position;
this.x_column_position = x_column_position;
this.clickable = clickable;
this.parent_dot = parent_dot;
this.original_parent_dot = parent_dot;
this.new_level_name = null;
this.new_level_id = null;
}
Dot.prototype.reset_position = function(x_column_position, y_row_position){
var bottom_left_x = BOTTOM_LEFT_X;
if (typeof this.clickable != 'undefined' && this.clickable === true) {
bottom_left_x = BOTTOM_LEFT_X + 75;
}
this.y_row_position = y_row_position;
this.x_column_position = x_column_position;
this.positionX = (bottom_left_x + (x_column_position*SPACING));
this.positionY = (BOTTOM_LEFT_Y - (y_row_position*SPACING));
console.log(this.fillStyle + " dot is being reset to row: " + this.y_row_position + ", column: " + this.x_column_position + ", with canvas coordinates of (" + this.positionX + ", " + this.positionY + ").");
};
ClickableDot.prototype = new Dot(); // Here's where the inheritance occurs
// ClickableDot.prototype.constructor = ClickableDot;
function ClickableDot(color, r, parent_dot, on_master_branch) {
Dot.call(this, color, r, 0, 0, parent_dot, true);
this.on_master_branch = on_master_branch;
this.original_on_master_branch = on_master_branch;
this.num_children = 0;
this.children_placed = 0;
this.children_placed_not_on_master = 0;
}
function PaletteDot(color, r) {
this.fillStyle = color;
this.radius = r;
this.positionX = null;
this.positionY = null;
this.sAngle = 0;
this.eAngle = 2 * Math.PI;
this.clockwise = false;
}
PaletteDot.prototype.draw = function(){
SHADOW_OFFSET_SIZE = 3;
SHADOW_BLUR_SIZE = 3;
if(currently_selected_palette_dot == this) {
// Draw with shadow;
ctx.save();
ctx.fillStyle = this.fillStyle;
ctx.shadowOffsetX = SHADOW_OFFSET_SIZE; // Sets the shadow offset x, positive number is right
ctx.shadowOffsetY = SHADOW_OFFSET_SIZE; // Sets the shadow offset y, positive number is down
ctx.shadowBlur = SHADOW_BLUR_SIZE; // Sets the shadow blur size
ctx.shadowColor = 'Black'; // Sets the shadow color
ctx.beginPath();
ctx.arc(this.positionX, this.positionY, this.radius, this.sAngle, this.eAngle, this.clockwise);
ctx.closePath();
ctx.fill();
ctx.restore();
}
else {
// Remove shadow
ctx.clearRect((this.positionX - this.radius), (this.positionY - this.radius), ((this.radius*2) + SHADOW_BLUR_SIZE + SHADOW_OFFSET_SIZE), ((this.radius*2) + SHADOW_BLUR_SIZE + SHADOW_OFFSET_SIZE));
ctx.fillStyle = this.fillStyle;
ctx.beginPath();
ctx.arc(this.positionX, this.positionY, this.radius, this.sAngle, this.eAngle, this.clockwise);
ctx.closePath();
ctx.fill();
}
};
Dot.prototype.draw = function(){
// console.log("Drawing the " + this.fillStyle + " dot.");
// console.log(this.fillStyle + " dot is: " + JSON.stringify(this));
// this.draw_surrounding_quadrant();
if(this.parent_dot != null) {
this.draw_line_to_parent();
}
ctx.fillStyle = this.fillStyle;
ctx.beginPath();
ctx.arc(this.positionX, this.positionY, this.radius, this.sAngle, this.eAngle, this.clockwise);
ctx.closePath();
ctx.fill();
};
Dot.prototype.draw_line_to_parent = function(){
if((this.on_master_branch && this.parent_dot.on_master_branch) || this.clickable == false) {
ctx.strokeStyle = "Yellow";
}
else {
ctx.strokeStyle = "Black";
}
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(this.positionX,this.positionY);
ctx.lineTo(this.parent_dot.positionX,this.parent_dot.positionY);
ctx.stroke();
};
Dot.prototype.draw_surrounding_quadrant = function(){
// ctx.fillStyle = this.fillStyle;
// ctx.globalAlpha = 0.3;
// ctx.beginPath();
// ctx.rect(this.positionX - this.radius, this.positionY- this.radius, this.radius*2, this.radius*2);
// ctx.closePath();
// ctx.fill();
// ctx.globalAlpha = 1;
};
Dot.prototype.calculate_num_children = function(){
var count_of_children = 0;
for(var i=0; i < current_dots.length; i++) {
if(current_dots[i].parent_dot == this) {
count_of_children++;
}
}
console.log("Num children of " + this.fillStyle + " is: " + count_of_children);
return count_of_children;
}
Dot.prototype.children = function(){
var children = [];
for(var z=0; z < current_dots.length; z++) {
if(current_dots[z].parent_dot != null && current_dots[z].parent_dot == this) {
// alert(current_dots[z].parent_dot.fillStyle + this.fillStyle);
children.push(current_dots[z]);
}
}
return children;
}
Dot.prototype.generate_string_of_children = function(rand_level_id){
var children = this.children();
var parent_name = this.new_level_name;
// "clickable_dot_838271_newlevelnumplaced = new ClickableDot('Navy', DOT_RADIUS, eval('parent_name'), true);"
if(children.length > 0) {
for(var y=0; y < children.length; y++) {
var child = children[y];
new_level_starting_positions_string = new_level_starting_positions_string + "clickable_dot_" + rand_level_id + "_" + new_level_num_placed + " = new ClickableDot('" + child.fillStyle + "', DOT_RADIUS, " + parent_name + ", " + child.on_master_branch + ");\n"
child.new_level_name = "clickable_dot_" + rand_level_id + "_" + new_level_num_placed;
new_level_starting_positions_string_array = new_level_starting_positions_string_array + child.new_level_name + ", "
new_level_num_placed++;
// Recursively remove all of the child's children
child.generate_string_of_children(rand_level_id);
}
}
}
Dot.prototype.generate_solution_string_of_children = function(rand_level_id){
// var dot_7_2 = new Dot("Gray", DOT_RADIUS, 1, 0, dot_7_1);
var children = this.children();
var parent_name = this.new_level_name;
if(children.length > 0) {
for(var y=0; y < children.length; y++) {
var child = children[y];
if(child.on_master_branch == true) {
new_level_solution_dots_string = new_level_solution_dots_string + "dot_" + rand_level_id + "_" + new_level_num_placed + " = new Dot('" + child.fillStyle + "', DOT_RADIUS, "+ new_level_num_placed + ", 0, " + parent_name + ");\n"
child.new_level_name = "dot_" + rand_level_id + "_" + new_level_num_placed;
new_level_num_placed++;
new_level_solution_dots_string_array = new_level_solution_dots_string_array + child.new_level_name + ", "
// Recursively remove all of the child's children
child.generate_solution_string_of_children(rand_level_id);
}
}
}
}
Dot.prototype.recursively_place_children = function(){
var children = this.children();
// console.log("Children of " + this.fillStyle + " are: " + JSON.stringify(children));
// console.log("Children of " + this.fillStyle + " length: " + children.length);
this.draw();
placed_dots.push(this);
for(var m=0; m < children.length; m++) {
var child = children[m];
console.log("Drawing => " + child.fillStyle);
if(child.on_master_branch == true) {
console.log(child.fillStyle + " on master branch");
child.reset_position(0, (child.parent_dot.y_row_position + 1));
}
else {
child.parent_dot.children_placed_not_on_master++;
if(child.parent_dot.on_master_branch == true && child.on_master_branch == false) {
// if(child.parent_dot.children_placed == 0) {
child.reset_position((child.parent_dot.children_placed_not_on_master), (child.parent_dot.y_row_position + 1));
// }
// child.reset_position((child.parent_dot.x_column_position + child.parent_dot.children_placed + 1), (child.parent_dot.y_row_position + 1));
}
else {
child.reset_position((child.parent_dot.x_column_position + child.parent_dot.children_placed), (child.parent_dot.y_row_position + 1));
}
var times_attempted = 0;
while(child.collides_with_placed_dots() == true) {
if(times_attempted > 10) {
alert("Sorry, it appears we've encountered a problem placing dots");
break;
}
if((child.x_column_position + 1) < 6) {
child.reset_position((child.x_column_position + 1), child.y_row_position);
}
else {
child.reset_position(child.x_column_position, (child.y_row_position + 1));
}
times_attempted++;
}
console.log(child.fillStyle + " not on master branch");
console.log("Children placed by parent:" + child.parent_dot.children_placed);
}
console.log("children placed for parent before: " + child.parent_dot.children_placed);
child.parent_dot.children_placed++;
console.log("children placed for parent after: " + child.parent_dot.children_placed);
child.recursively_place_children();
}
}
Dot.prototype.remove_children = function(){
var children = this.children();
console.log("Checking if I should remove " + children.length +" children: " + JSON.stringify(children));
if(children.length > 0) {
for(var y=0; y < children.length; y++) {
var child = children[y];
if(child.on_master_branch == true) {
// console.log("The child: " + child.fillStyle + " is on the master branch so I am not removing it");
// console.log("Parent dot being reset for " + child.fillStyle + " to: " + this.parent_dot.fillStyle);
child.parent_dot = this.parent_dot;
if(child.parent_dot == null) {
child.reset_position(0, 0);
}
// console.log("The " + current_dots.length + " current dots are: " + JSON.stringify(current_dots));
}
else {
console.log("Removing child: " + child.fillStyle);
//Remove the child itself
child.remove_self();
// Recursively remove all of the child's children
child.remove_children();
}
}
}
// console.log("At end of remove_children " + current_dots.length + " current dots are: " + JSON.stringify(current_dots));
}
Dot.prototype.add_self_and_child_to_master_branch = function(true_or_false){
var children = this.children();
console.log("Adding " + this.fillStyle + " dot to master branch");
this.on_master_branch = true_or_false;
if(children.length > 0) {
for(f=0; f < 1; f++) {
var child = children[f];
child.add_self_and_child_to_master_branch(true_or_false);
}
}
}
Dot.prototype.remove_self_and_child_from_master_branch = function(){
var children = this.children();
console.log("Adding " + this.fillStyle + " dot to master branch");
this.on_master_branch = false;
if(children.length > 0) {
for(g=0; g < children.length; g++) {
var child = children[g];
child.remove_self_and_child_from_master_branch();
}
}
}
Dot.prototype.is_root_dot = function(){
if(this.parent_dot === null) {
return true;
}
else {
return false;
}
}
// Dot.prototype.initialize_children = function(){
// var children = this.children_new_level();
//
// if(children.length > 0) {
// for(var y=0; y < children.length; y++) {
// var child = children[y];
// child.
//
// child.initialize_children();
//
// }
// }
// }
Dot.prototype.remove_self = function(){
// console.log("Before removing self, " + current_dots.length + " current dots are: " + JSON.stringify(current_dots));
for(r = 0; r < current_dots.length; r++) {
if(current_dots[r] == this) {
console.log("I am removing myself, currently_clicked " + currently_clicked.fillStyle);
// alert("Starting position dots before remove: " + current_level.starting_position_dots);
removed_dots.push(current_dots[r]);
current_dots.splice(r, 1);
// alert("Starting position dots before remove: " + current_level.starting_position_dots);
//
// alert("Removed dots: " + JSON.stringify(removed_dots));
break;
}
}
// console.log("Before removing self, " + current_dots.length + " current dots are: " + JSON.stringify(current_dots));
}
Dot.prototype.set_self_and_all_parents_to_master_branch = function(){
this.on_master_branch = true;
console.log("Setting " + this.fillStyle + " dot to on master branch");
if(this.parent_dot != null) {
this.parent_dot.set_self_and_all_parents_to_master_branch();
}
}
Dot.prototype.collides_with_placed_dots = function(){
var collides = false;
for(var v=0; v < placed_dots.length; v++) {
if (pointInCircle(placed_dots[v].positionX, placed_dots[v].positionY, this) == true && placed_dots[v] != this) {
console.log(this.fillStyle + " collides with already placed " + placed_dots[v].fillStyle);
console.log("(" + placed_dots[v].positionX + ", " + placed_dots[v].positionY + ") " + "(" + this.positionX + ", " + this.positionY + ")");
collides = true;
break;
}
}
return collides;
}
Dot.prototype.is_descendant_of = function(ancestor_dot){
var parent_to_check = this.parent_dot;
var is_descendant = false;
while(parent_to_check != null) {
if(parent_to_check == ancestor_dot) {
is_descendant = true;
break;
}
else {
parent_to_check = parent_to_check.parent_dot;
}
}
return is_descendant;
}
Dot.prototype.already_has_child_on_master = function(){
var children = this.children();
var has_child_on_master = false;
for(n = 0; n < children.length; n++) {
if(children[n].on_master_branch == true) {
has_child_on_master = true;
break;
}
}
return has_child_on_master;
}
function pointInCircle(clickPointX, clickPointY, shape) {
var distX = Math.abs(clickPointX - shape.positionX),
distY = Math.abs(clickPointY - shape.positionY),
dist = Math.sqrt(distX * distX + distY * distY);
return dist < shape.radius;
}
function checkCollisionWithPaletteDots(e) {
if(level_maker_on == true) {
for(var pd = 0; pd < color_palette_dots.length; pd++){
if (pointInCircle(e.offsetX, e.offsetY, color_palette_dots[pd]) == true) {
console.log(color_palette_dots[pd].fillStyle + " palette dot clicked!");
currently_selected_palette_dot = color_palette_dots[pd];
add_palette_dots();
// If it is the first dot make it the root dot and draw it
if(current_dots == null) {
var root_level_maker_dot = new ClickableDot(color_palette_dots[pd].fillStyle, DOT_RADIUS, null, true);
current_dots = [root_level_maker_dot];
recursively_place_dots();
currently_selected_palette_dot = null;
$(".level_maker_instruction").hide();
$(".level_maker_instruction#choose_color").show();
}
else {
$(".level_maker_instruction#choose_color").hide();
$(".level_maker_instruction#choose_parent").show();
}
}
}
}
}
function checkCollisionWithClickableDots(e) {
if(current_dots != null) {
for(var num = 0; num < current_dots.length; num++){
// alert("im in here: " + num);
if (pointInCircle(e.offsetX, e.offsetY, current_dots[num]) == true) {
if(level_maker_on == true) {
if(currently_selected_palette_dot == null) {
alert("You must choose a color dot before you choose a dot to connect it to.");
}
else {
if(current_dots[num].on_master_branch == true) {
if(current_dots[num].already_has_child_on_master() == false) {
var answer = confirm("Do you want to add this to the solution line? Click cancel if you want to add it but not to the solution line.");
if (answer){
// Add to solution line
current_dots.push(new ClickableDot(currently_selected_palette_dot.fillStyle, DOT_RADIUS, current_dots[num], true));
}
else{
// Don't add to solution line
current_dots.push(new ClickableDot(currently_selected_palette_dot.fillStyle, DOT_RADIUS, current_dots[num], false));
}
}
else {
// Don't add to solution line
current_dots.push(new ClickableDot(currently_selected_palette_dot.fillStyle, DOT_RADIUS, current_dots[num], false));
}
}
else {
current_dots.push(new ClickableDot(currently_selected_palette_dot.fillStyle, DOT_RADIUS, current_dots[num], false));
}
recursively_place_dots();
currently_selected_palette_dot = null;
$(".level_maker_instruction#choose_parent").hide();
$(".level_maker_instruction#choose_color").show();
add_palette_dots();
}
}
else {
if (move_in_progress != null) {
assign_click(current_dots[num]);
if(currently_clicked != null) {
if (required_secondary_click_not_chosen_yet() == true) {
show_secondary_instructions();
}
else if(required_tertiary_click_not_chosen_yet() == true && secondary_clicked == top_of_column(0) && options_for_master_branch_on_rebase() > 1) {
show_tertiary_instructions();
}
else {
make_move();
}
}
}
else {
alert("You need to choose a move before you select a dot!");
}
}
}
}
}
}
function assign_click(dot) {
if (currently_clicked == null) {
var click_allowed = allowed_as_clicked(dot);
if (click_allowed[0] == true) {
currently_clicked = dot;
}
else {
alert(click_allowed[1]);
}
}
else if (currently_clicked != null && secondary_clicked == null) {
var click_allowed = allowed_as_secondary_clicked(dot);
if (click_allowed[0] == true) {
secondary_clicked = dot;
}
else {
alert(click_allowed[1]);
}
}
else if (currently_clicked != null && secondary_clicked != null) {
var click_allowed = allowed_as_tertiary_clicked(dot);
if (click_allowed[0] == true) {
tertiary_clicked = dot;
}
else{
alert(click_allowed[1]);
}
}
}
function allowed_as_clicked(dot) {
response_array = [true];
if(move_in_progress == "rebase" && dot.is_root_dot() == true) {
response_array = [false, "You cannot move the bottommost dot with a rebase. Choose again."];
}
return response_array;
}
function allowed_as_secondary_clicked(dot) {
response_array = [true];
if(move_in_progress == "rebase" && dot.is_descendant_of(currently_clicked) == true) {
response_array = [false, "You cannot rebase on top of a dot that is on top of the first one you clicked. Choose again."];
}
return response_array;
}
function allowed_as_tertiary_clicked(dot) {
response_array = [true];
return response_array;
}
//////// END DOTS
////////////////////////////////////////////////////////////////////////////
function required_secondary_click_not_chosen_yet() {
if((move_in_progress == "rebase") && secondary_clicked == null) { //|| move_in_progress == "reset"
return true;
}
else {
return false;
}
}
function required_tertiary_click_not_chosen_yet() {
if((move_in_progress == "rebase") && tertiary_clicked == null) {
return true;
}
else {
return false;
}
}
function show_secondary_instructions() {
$(".first_instructions").hide();
$(".instructions#" + move_in_progress + " .secondary_instructions").show();
}
function show_tertiary_instructions() {
options_for_master_branch_on_rebase();
$(".instructions#" + move_in_progress + " .secondary_instructions").hide();
$(".instructions#" + move_in_progress + " .tertiary_instructions").show();
}
function Level(rebases, resets, copies, removes, cherry_picks, solution_dots, starting_position_dots, level_number, level_name) {
this.rebases = rebases;
this.rebase_used = 0;
this.resets = resets;
this.reset_used = 0;
this.copies = copies;
this.copy_used = 0;
this.removes = removes;
this.remove_used = 0;
this.cherry_picks = cherry_picks;
this.cherry_pick_used = 0;
this.solution_dots = solution_dots;
this.starting_position_dots = starting_position_dots;
this.level_number = level_number;
this.level_name = level_name;
}
Level.prototype.begin = function(){
$("#level_description").html("<h3>Level " + this.level_number + ": " + this.level_name + "</h3>");
// Add back removed dots
// alert("Removed dots length: " + removed_dots.length)
// alert("Current dots length before: " + current_dots.length)
current_dots = current_dots.concat(removed_dots);
this.starting_position_dots = this.starting_position_dots.concat(removed_dots);
// alert("Current dots length after: " + current_dots.length)
// alert("Starting position dots: " + this.starting_position_dots.length);
clear_whole_canvas();
this.reset_starting_dots();
removed_dots = [];
current_level = this;
current_dots = this.starting_position_dots;
// alert("Current dots length after set to starting position dots: " + current_dots.length);
this.restart_moves_counters();
// place_all_dots();
for (i=0; i < this.solution_dots.length ; i++) {
this.solution_dots[i].draw();
}
recursively_place_dots();
draw_dividing_line();
openMoveOptions();
};
Level.prototype.restart_moves_counters = function(){
this.rebase_used = 0;
this.reset_used = 0;
this.copy_used = 0;
this.remove_used = 0;
this.cherry_pick_used = 0;
};
function draw_dividing_line() {
ctx.save();
ctx.lineWidth = 3;
ctx.strokeStyle = "Gray";
ctx.beginPath();
ctx.moveTo(100,800);
ctx.lineTo(100,280);
ctx.stroke();
ctx.restore();
ctx.save();
ctx.fillStyle = "Black";
ctx.translate(136, 770);
ctx.font = "12px sans-serif";
ctx.rotate(-Math.PI/2);
ctx.textAlign = "center";
ctx.fillText("Your Solution Line", 100, 0);
ctx.restore();
ctx.save();
ctx.fillStyle = "Black";
ctx.translate(62, 745);
ctx.font = "12px sans-serif";
ctx.rotate(-Math.PI/2);
ctx.textAlign = "center";
ctx.fillText("Goal Line", 100, 0);
ctx.restore();
ctx.save();
ctx.fillStyle = "Black";
ctx.translate(135, 790);
ctx.font = "12px sans-serif";
ctx.textAlign = "center";
ctx.fillText("THESE DOTS ARE CLICKABLE DURING MOVES", 130, 0);
ctx.restore();
}
Level.prototype.reset_starting_dots = function(){
// alert("Reseting Starting dots length is: " + this.starting_position_dots.length);
for(t=0; t < this.starting_position_dots.length; t++) {
var dot = this.starting_position_dots[t];
dot.parent_dot = dot.original_parent_dot;
dot.on_master_branch = dot.original_on_master_branch;
}
};
Level.prototype.solution_colors = function(){
var solution_colors_array = [];
for (i=0; i < this.solution_dots.length ; i++) {
var dot = this.solution_dots[i];
solution_colors_array[dot.y_row_position] = dot.fillStyle;
}
return solution_colors_array;
};
////////////////////////////////////////// LEVEL 1 DEFINITION
var dot_1_1 = new Dot("Navy", DOT_RADIUS, 0, 0, null);
var dot_1_2 = new Dot("Red", DOT_RADIUS, 1, 0, dot_1_1);
var dot_1_3 = new Dot("Green", DOT_RADIUS, 2, 0, dot_1_2);
level1_solution = [dot_1_1, dot_1_2, dot_1_3];
var clickableDot_1_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_1_2 = new ClickableDot("Red", DOT_RADIUS, clickableDot_1_1, true);
var clickableDot_1_3 = new ClickableDot("Green", DOT_RADIUS, clickableDot_1_1, false);
level1_starting_dots = [clickableDot_1_1, clickableDot_1_2, clickableDot_1_3]
level1 = new Level(0, 0, 0, 0, 1, level1_solution, level1_starting_dots, 1, "Learn To Cherry-Pick");
all_levels.push(level1);
current_level = level1;
current_dots = level1_starting_dots;
///////////////////////////////////////// END LEVEL 1 DEFINITION
////////////////////////////////////////// LEVEL 2 DEFINITION
var dot_2_1 = new Dot("Navy", DOT_RADIUS, 0, 0, null);
var dot_2_2 = new Dot("Red", DOT_RADIUS, 1, 0, dot_2_1);
var dot_2_3 = new Dot("Green", DOT_RADIUS, 2, 0, dot_2_2);
var dot_2_4 = new Dot("Orange", DOT_RADIUS, 3, 0, dot_2_3);
level2_solution = [dot_2_1, dot_2_2, dot_2_3, dot_2_4];
var clickableDot_2_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_2_2 = new ClickableDot("Green", DOT_RADIUS, clickableDot_2_1, false);
var clickableDot_2_3 = new ClickableDot("Red", DOT_RADIUS, clickableDot_2_1, true);
var clickableDot_2_4 = new ClickableDot("Orange", DOT_RADIUS, clickableDot_2_2, false);
level2_starting_dots = [clickableDot_2_1, clickableDot_2_2, clickableDot_2_3, clickableDot_2_4];
level2 = new Level(1, 0, 0, 0, 0, level2_solution, level2_starting_dots, 2, "Learn To Rebase");
all_levels.push(level2);
// current_level = level2;
// current_dots = level2_starting_dots;
///////////////////////////////////////// END LEVEL 2 DEFINITION
////////////////////////////////////////// LEVEL 3 DEFINITION
var dot_3_1 = new Dot("Navy", 15, 0, 0, null);
var dot_3_2 = new Dot("Green", 15, 1, 0, dot_3_1);
level3_solution = [dot_3_1, dot_3_2];
var clickableDot_3_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_3_2 = new ClickableDot("Red", DOT_RADIUS, clickableDot_3_1, true);
var clickableDot_3_3 = new ClickableDot("Green", DOT_RADIUS, clickableDot_3_2, true);
level3_starting_dots = [clickableDot_3_1, clickableDot_3_2, clickableDot_3_3];
level3 = new Level(0, 0, 0, 1, 0, level3_solution, level3_starting_dots, 3, "Learn To Remove");
all_levels.push(level3);
// current_level = level3;
// current_dots = level3_starting_dots;
///////////////////////////////////////// END LEVEL 3 DEFINITION
////////////////////////////////////////// LEVEL 4 DEFINITION
var dot_4_1 = new Dot("Navy", DOT_RADIUS, 0, 0, null);
var dot_4_2 = new Dot("Green", DOT_RADIUS, 1, 0, dot_4_1);
var dot_4_3 = new Dot("Red", DOT_RADIUS, 2, 0, dot_4_2);
var dot_4_4 = new Dot("Orange", DOT_RADIUS, 3, 0, dot_4_3);
level4_solution = [dot_4_1, dot_4_2, dot_4_3, dot_4_4];
var clickableDot_4_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_4_2 = new ClickableDot("Green", DOT_RADIUS, clickableDot_4_1, true);
var clickableDot_4_3 = new ClickableDot("Red", DOT_RADIUS, clickableDot_4_2, false);
var clickableDot_4_4 = new ClickableDot("Black", DOT_RADIUS, clickableDot_4_2, true);
var clickableDot_4_5 = new ClickableDot("Orange", DOT_RADIUS, clickableDot_4_3, false);
level4_starting_dots = [clickableDot_4_1, clickableDot_4_2, clickableDot_4_3, clickableDot_4_4, clickableDot_4_5];
level4 = new Level(0, 1, 0, 0, 0, level4_solution, level4_starting_dots, 4, "Learn To Reset");
all_levels.push(level4);
// current_level = level4;
// current_dots = level4_starting_dots;
///////////////////////////////////////// END LEVEL 4 DEFINITION
////////////////////////////////////////// LEVEL 5 DEFINITION
var dot_5_1 = new Dot("Navy", DOT_RADIUS, 0, 0, null);
var dot_5_2 = new Dot("Green", DOT_RADIUS, 1, 0, dot_5_1);
var dot_5_3 = new Dot("Red", DOT_RADIUS, 2, 0, dot_5_2);
var dot_5_4 = new Dot("Orange", DOT_RADIUS, 3, 0, dot_5_3);
var dot_5_5 = new Dot("Purple", DOT_RADIUS, 4, 0, dot_5_4);
level5_solution = [dot_5_1, dot_5_2, dot_5_3, dot_5_4, dot_5_5];
var clickableDot_5_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_5_2 = new ClickableDot("Green", DOT_RADIUS, clickableDot_5_1, true);
var clickableDot_5_3 = new ClickableDot("Red", DOT_RADIUS, clickableDot_5_1, false);
var clickableDot_5_4 = new ClickableDot("Orange", DOT_RADIUS, clickableDot_5_2, false);
var clickableDot_5_5 = new ClickableDot("Purple", DOT_RADIUS, clickableDot_5_4, false);
level5_starting_dots = [clickableDot_5_1, clickableDot_5_2, clickableDot_5_3, clickableDot_5_4, clickableDot_5_5];
level5 = new Level(1, 0, 0, 0, 1, level5_solution, level5_starting_dots, 5, "Use 2 Moves");
all_levels.push(level5);
// current_level = level5;
// current_dots = level5_starting_dots;
///////////////////////////////////////// END LEVEL 5 DEFINITION
////////////////////////////////////////// LEVEL 6 DEFINITION
var dot_6_1 = new Dot("Navy", DOT_RADIUS, 0, 0, null);
var dot_6_2 = new Dot("Red", DOT_RADIUS, 1, 0, dot_6_1);
var dot_6_3 = new Dot("Purple", DOT_RADIUS, 2, 0, dot_6_2);
level6_solution = [dot_6_1, dot_6_2, dot_6_3];
var clickableDot_6_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_6_2 = new ClickableDot("Green", DOT_RADIUS, clickableDot_6_1, true);
var clickableDot_6_3 = new ClickableDot("Red", DOT_RADIUS, clickableDot_6_2, true);
var clickableDot_6_4 = new ClickableDot("Orange", DOT_RADIUS, clickableDot_6_2, false);
var clickableDot_6_5 = new ClickableDot("Purple", DOT_RADIUS, clickableDot_6_4, false);
level6_starting_dots = [clickableDot_6_1, clickableDot_6_2, clickableDot_6_3, clickableDot_6_4, clickableDot_6_5];
level6 = new Level(1, 0, 0, 2, 0, level6_solution, level6_starting_dots, 6, "Order Matters");
all_levels.push(level6);
// current_level = level6;
// current_dots = level6_starting_dots;
///////////////////////////////////////// END LEVEL 6 DEFINITION
////////////////////////////////////////// LEVEL 7 DEFINITION
// Level(rebases, resets, copies, removes, cherry_picks, solution_dots, starting_position_dots, level_number, level_name)
var dot_7_1 = new Dot("Navy", DOT_RADIUS, 0, 0, null);
var dot_7_2 = new Dot("Gray", DOT_RADIUS, 1, 0, dot_7_1);
var dot_7_3 = new Dot("Orange", DOT_RADIUS, 2, 0, dot_7_2);
var dot_7_4 = new Dot("Purple", DOT_RADIUS, 3, 0, dot_7_3);
var dot_7_5 = new Dot("Pink", DOT_RADIUS, 4, 0, dot_7_4);
var dot_7_6 = new Dot("Green", DOT_RADIUS, 5, 0, dot_7_5);
var dot_7_7 = new Dot("Black", DOT_RADIUS, 6, 0, dot_7_6);
level7_solution = [dot_7_1, dot_7_2, dot_7_3, dot_7_4, dot_7_5, dot_7_6, dot_7_7];
var clickableDot_7_1 = new ClickableDot("Navy", DOT_RADIUS, null, true);
var clickableDot_7_2 = new ClickableDot("Purple", DOT_RADIUS, clickableDot_7_1, true);
var clickableDot_7_3 = new ClickableDot("Black", DOT_RADIUS, clickableDot_7_1, false);
var clickableDot_7_4 = new ClickableDot("Gray", DOT_RADIUS, clickableDot_7_1, false);
var clickableDot_7_5 = new ClickableDot("Green", DOT_RADIUS, clickableDot_7_3, false);
var clickableDot_7_6 = new ClickableDot("Red", DOT_RADIUS, clickableDot_7_4, false);
var clickableDot_7_7 = new ClickableDot("Pink", DOT_RADIUS, clickableDot_7_6, false);
var clickableDot_7_8 = new ClickableDot("Orange", DOT_RADIUS, clickableDot_7_6, false);
level7_starting_dots = [clickableDot_7_1, clickableDot_7_2, clickableDot_7_3, clickableDot_7_4, clickableDot_7_5, clickableDot_7_6, clickableDot_7_7, clickableDot_7_8];
level7 = new Level(3, 1, 0, 1, 1, level7_solution, level7_starting_dots, 7, "A Hard One. Can you do it?");
all_levels.push(level7);
// current_level = level7;
// current_dots = level7_starting_dots;
///////////////////////////////////////// END LEVEL 7 DEFINITION
////////////////////////////////////////// LEVEL 8 DEFINITION
dot_8_0 = new Dot('Steelblue', DOT_RADIUS, 0, 0, null);
dot_8_1 = new Dot('Pink', DOT_RADIUS, 1, 0, dot_8_0);
dot_8_2 = new Dot('Purple', DOT_RADIUS, 2, 0, dot_8_1);
dot_8_3 = new Dot('Black', DOT_RADIUS, 3, 0, dot_8_2);
clickable_dot_8_0 = new ClickableDot('Steelblue', DOT_RADIUS, null, true);
clickable_dot_8_1 = new ClickableDot('Pink', DOT_RADIUS, clickable_dot_8_0, false);
clickable_dot_8_2 = new ClickableDot('Purple', DOT_RADIUS, clickable_dot_8_1, false);
clickable_dot_8_3 = new ClickableDot('Green', DOT_RADIUS, clickable_dot_8_0, true);
clickable_dot_8_4 = new ClickableDot('Black', DOT_RADIUS, clickable_dot_8_3, false);
level8_solution = [dot_8_0, dot_8_1, dot_8_2, dot_8_3];
level8_starting_dots = [clickable_dot_8_0, clickable_dot_8_1, clickable_dot_8_2, clickable_dot_8_3, clickable_dot_8_4];
level8 = new Level(1, 1, 0, 0, 0, level8_solution, level8_starting_dots, 8, 'The Level Maker Lives!!!');
all_levels.push(level8);
////////////////////////////////////////// END LEVEL 8 DEFINITION
dot_9_0 = new Dot('Black', DOT_RADIUS, 0, 0, null);
dot_9_1 = new Dot('Blue', DOT_RADIUS, 1, 0, dot_9_0);
dot_9_2 = new Dot('Green', DOT_RADIUS, 2, 0, dot_9_1);
dot_9_3 = new Dot('Red', DOT_RADIUS, 3, 0, dot_9_2);
clickable_dot_9_0 = new ClickableDot('Black', DOT_RADIUS, null, true);
clickable_dot_9_1 = new ClickableDot('Red', DOT_RADIUS, clickable_dot_9_0, true);
clickable_dot_9_2 = new ClickableDot('Green', DOT_RADIUS, clickable_dot_9_1, true);
clickable_dot_9_3 = new ClickableDot('Blue', DOT_RADIUS, clickable_dot_9_2, true);
level9_solution = [dot_9_0, dot_9_1, dot_9_2, dot_9_3];
level9_starting_dots = [clickable_dot_9_0, clickable_dot_9_1, clickable_dot_9_2, clickable_dot_9_3];
level9 = new Level(3, 1, 0, 0, 0, level9_solution, level9_starting_dots, 9, 'RGB fun');
all_levels.push(level9);
///////////////////////////////////////////////////////////////////
dot_10_0 = new Dot('Red', DOT_RADIUS, 0, 0, null);
clickable_dot_10_0 = new ClickableDot('Mediumpurple', DOT_RADIUS, null, true);
clickable_dot_10_1 = new ClickableDot('Olive', DOT_RADIUS, clickable_dot_10_0, true);
clickable_dot_10_2 = new ClickableDot('Red', DOT_RADIUS, clickable_dot_10_1, true);
clickable_dot_10_3 = new ClickableDot('Black', DOT_RADIUS, clickable_dot_10_2, true);
clickable_dot_10_4 = new ClickableDot('Chocolate', DOT_RADIUS, clickable_dot_10_3, true);