| 12
 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
 
 | <!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8 />
    <title>jeu</title>
  </head>
  <style>
    .carre {
      position: absolute;
      left: 10pt;
      top: 10pt;
      visibility: hidden;
    }
  </style>
  <body>
 
    <img id="c" class="carre" src="carre.png" />
    <script>
function Rectangle(x, y){
  this.autreRectangle = [];
  this.dx = 0;
  this.dy = 0;
  this.x = x;
  this.y = y;
  this.img = document.getElementById("c").cloneNode(true);
  this.img.style.visibility = "visible";
  document.documentElement.appendChild(this.img);
}
 
Rectangle.prototype = {
  pas: function() {
	this.dx += this.x+1;
	this.dy += this.y+1;
    this.autreRectangle.push(new Rectangle(this.dx, this.dy));
  }
}
 
var rectangle = new Rectangle(200, 300);
rectangle.pas();
 
// liste des autres rectangles
console.log(rectangle.autreRectangle);
 
// augmenter le pas du premier rectangle au dessus
rectangle.autreRectangle[0].pas();
 
// rectangle de base
console.log(rectangle);
 
 
 </script>
  </body>
</html> | 
Partager