Spaces:
Running
Running
File size: 1,868 Bytes
87b3b3a |
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 |
# The Chameleon Way
## someone328
```javascript
// using canvas to draw the line
var ctx = map.getCanvasContext();
ctx.beginPath();
ctx.strokeStyle = color; //make lasers colored
ctx.lineWidth = 5;
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
//color switcher by telephone
player.setColor('red');
player.setPhoneCallback(function(){
var color = player.getColor();
switch(color)
{
case 'red':
player.setColor('yellow');
break;
case 'yellow':
player.setColor('teal');
break;
case 'teal':
player.setColor('red');
break;
}
});
```
## esolitos
```javascript
ctx.strokeStyle = color;
//---
var j = 0;
var colors = ['red', 'yellow', 'teal'];
player.setPhoneCallback( function(){
player.setColor( colors[ (j++)%3 ] );
} );
```
## mmccall0813
```javascript
ctx.strokeStyle = color;
//
var player = map.getPlayer();
player.setPhoneCallback(function(){
if(player.getColor() == 'teal'){player.setColor('red')}else{
if(player.getColor() == 'red'){player.setColor('yellow')}else{
if(player.getColor() == 'yellow'){player.setColor('teal')}else{
player.setColor('teal')}}}});
```
# Function Redefinition
## Jhack (giacgbj)
Nothing in the first area.
The following code in the second area:
```javascript
getRandomInt = function(){return 600;};
```
# Closures
## ZER0
```js
// using canvas to draw the line
var ctx = map.getCanvasContext();
ctx.beginPath();
ctx.strokeStyle = 'white';
ctx.lineWidth = 5;
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
// take advantages of the closure create by `map.createLine`
// so all lasers will be of the same color of the player
color = player.getColor();
```
|