forked from sf-wdi-25/kyrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kyrel.js
161 lines (125 loc) · 3.45 KB
/
kyrel.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
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
var row, colors, kyrel, return_value, rando;
/*
If you need variables, please declare them ^up here^!
That way, you will be able to check them out in the Chrome console.
Just don't use any that I'm already using!
INSTRUCTIONS:
- Write all of your code inside the "main" function below.
- Use this file to build/test your programs.
You can call: moveRight(), moveLeft(),
useGreen(), useBlue(), draw(), erase(),
onGreen(), onBlue()
You can also (re)configure the initial state of the row:
'.' => empty
'b' => blue
'g' => green
*/
var initial_state = [ '.', '.', '.', '.', '.' ];
function main(n) {
//////////////////////////////////
//// ////
//// v YOUR CODE BELOW HERE v ////
//// ////
//////////////////////////////////
//////////////////////////////////
//// ////
//// ^ YOUR CODE ABOVE HERE ^ ////
//// ////
//////////////////////////////////
} // END MAIN
//////////////////////////////
//
// BEWARE, INNER WORKINGS BELOW
// Feel free to read around, but just don't break anything :)
//
//////////////////////////////
row = {
x: 5
}
colors = {
empty: '#fff',
gray: '#ccc',
blue: 'blue',
green: 'green'
};
kyrel = {
x: 0,
color: colors.blue
};
function play() {
return_value = main(rando);
if(typeof return_value !== 'undefined') {
$(".instructions").append("<div><strong>returned "+return_value+"</strong></div>");
}
$(".play").hide();
$(".reset").show();
}
function initializeRow() {
for(var j=0; j<row.x; j++) {
var cell = $("tr").find("td").eq(j);
if(initial_state[j] == 'b') {
cell.html('<div class="dot dot-blue"></div>')
cell.find('.dot').css('background', colors.blue);
} else if(initial_state[j] == 'g') {
cell.html('<div class="dot dot-green"></div>')
cell.find('.dot').css('background', colors.green);
} else {
cell.find(".dot").remove();
}
}
}
function updateRow() {
$("td").css('border-color', colors.gray);
currentSquare().css('border-color', kyrel.color);
}
function currentSquare() {
return $("tr").find("td").eq(kyrel.x);
}
function moveLeft() {
$(".instructions").append("<div>moveLeft</div>");
if(kyrel.x > 0) {
kyrel.x = kyrel.x - 1;
updateRow();
}
}
function moveRight() {
$(".instructions").append("<div>moveRight</div>");
if(kyrel.x < row.x - 1) {
kyrel.x = kyrel.x + 1;
updateRow();
}
}
function draw() {
$(".instructions").append("<div>draw</div>");
currentSquare().html('<div class="dot"></div>')
currentSquare().find('.dot').css('background', kyrel.color).addClass('dot-'+kyrel.color);
}
function erase() {
$(".instructions").append("<div>erase</div>");
currentSquare().find(".dot").remove();
}
function useBlue() {
$(".instructions").append("<div>useBlue</div>");
kyrel.color = colors.blue;
updateRow();
}
function useGreen() {
$(".instructions").append("<div>useGreen</div>");
kyrel.color = colors.green;
updateRow();
}
function onBlue() {
return currentSquare().find(".dot.dot-blue").length > 0;
}
function onGreen() {
return currentSquare().find(".dot.dot-green").length > 0;
}
$(document).ready(function() {
rando = parseInt(Math.random()*10)
console.log("Our random number for this run is "+rando);
//attach listeners
$(".play").click(play);
// Start it up!
initializeRow();
updateRow();
});