Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a prototype for Level #117

Merged
merged 6 commits into from
Aug 5, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions javascript/levels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
function Level(home, backgroundLayers, obstaclesLayer){
this._backgrounds = backgroundLayers;
this.obstacleLayer = obstaclesLayer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we can have several obstacle layers

this._obstacles = createObstacles(obstaclesLayer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this line do?

this._name = name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does name com from?

this._score = 0;
}

Level.prototype = {

show: function(){
show_layer(this.obstaclesLayer);
for (layer in this.backgrounds){
show_layer(layer);
}
},

hide: function(){
hide_layer(this.obstaclesLayer);
for (layer in this.backgrounds){
hide_layer(layer);
}
},

getBackgrounds(): function(){
return this._backgrounds;
},

getObstacles: function(){
return this._obstacles;
},

getName(): function(){
return this._name;
},

getScore(): function{
return this_score;
},

start(): function(){
//Needs to be Implemented
},

stop(): function(){
// Needs to be Implemented
},

}

var all_levels,current_level;

function getAllLevels(){
return all_levels;
}

function newLevel(name,backgroundLayers,obstaclesLayer){
return new Level(name,backgroundLayers,obstaclesLayer);
}

function AlllevelObjects(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be executed several times? Can you remove this function and make the spec a global variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everytime you start a game this function should be executed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect getAllLevels to return the same levels all the time.
Thus, I expect AlllevelObjects() to be called only once.

There are several ways to meet this expectation, which I see:

  • Run this function in this file when it is loaded and make it "private"
  • Remove the function around the for-loop and execute the for-loop when the file is loaded.

What is your perspective on this?

// Need to be properly Modified
levels = ["level1","level2"];

backgrounds = {
"level1":[],
"level2":[]
};

obstacles = {
"level1":"obstacle for level1",
"level2":"obstacle for level2",
};

for(level in levels){
all_levels[level] = newLevel(level,backgrounds[level],obstacles[level]);
}
}

function setCurrentLevel(name){
current_level = all_levels[name];
}

function getCurrentLevel(){
return current_level;
}