-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
In other highlevel programming languages(like C++) information hiding is often a standard possibility. In javascript information hiding could be done by using closure.
A class structure seen in the next picture
could be done as follows:
function myClass()
{
// Private member variable
var myAttribute = 0;
// First method
this.setAttribute = function(attribute)
{
myAttribute = attribute;
}
// Second method
this.getAttribute = function()
{
return myAttribute;
}
}
// Instance
myInstance = new myClass();
// Outputs 0
console.log(myInstance.getAttribute());
myInstance.setAttribute(42);
// Outputs 42
console.log(myInstance.getAttribute());
Because of javascripts closure ability, the variable myAttribute in the code snippet should be private. This means that a direct access to the variable with e.g. myInstance.myAttribute should not be possible. A self made access to the variable would offer the class methods this.setAttribute and this.getAttribute.
The user interaction part should look like the content as seen below by starting "index.html" in a web browser.
- Every cup in the picture should be clickable.
- Only one cup should be the right one and left clicking it, would give positive points. The other cups would give negative points if left clicked.
- The riddle offers an option for compensating negative points. The answer would be checked automatically by giving the correct input.
- Positive points for correct cup would be 50 when left clicked.
- Positive points for riddle would be 30 when answered correctly.
- Negative points for incorrect cups would be -15 when left clicked.
- Maximal rounds would be 5 when played to the end.
🅱️ utton "RESTART" should refreshe the page.
To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
-
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
Sources:
-
What is Class Diagram? by Copyright © 1999-2019 by Visual Paradigm. All rights reserved.
-
Catacomb Riddles - unless otherwise stated, the content of the page is licensed under Creative Commons Attribution-ShareAlike 3.0 License and Powered by Wikidot.com