-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkg_stamps.js
69 lines (55 loc) · 1.59 KB
/
kg_stamps.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
/**
* TODO: MAKE IT WWORK RIGHT
*/
"use strict";
/*
New Perspectives on HTML5, CSS3, and JavaScript 6th Edition
Tutorial 14
Case Problem 4
Filename: kg_stamps.js
Author: Hesbon Osoro
Date: 12/11/22
*/
// Custom game object
function game() {
this.stamps = [];
this.currentTool = "brush";
this.currentShape = "square";
this.currentSize = 5;
this.currentShade = 1.0;
}
// stamp Object Prototype
function stamp(shape, size, shade) {
this.shape = shape;
this.size = size;
this.shade = shade;
}
// Method to add a stamp to the game object's stamps array
stamp.prototype.addToGame = function (game) {
game.stamps.push(this);
};
// Method to remove all stamps from the game object's stamps array
game.prototype.removeStamps = function () {
this.stamps = [];
};
// Create a new game object
var game1 = new game();
// Add a click event handler to the addStamp button
window.addEventListener("load", function () {});
/*---- Added Methods ---*/
// Method to return the x-coordinate of a mouse click within an element
Event.prototype.elementX = function () {
var rectObject = this.target.getBoundingClientRect();
return this.clientX - rectObject.left;
};
// Method to return the y-coordinate of a mouse click within an element
Event.prototype.elementY = function () {
var rectObject = this.target.getBoundingClientRect();
return this.clientY - rectObject.top;
};
/* Method added to any DOM element that removes all child nodes of element */
HTMLElement.prototype.removeChildren = function () {
while (this.firstChild) {
this.removeChild(this.firstChild);
}
};