parent
b0e4b43d9f
commit
fe1a7cf3a9
@ -1,9 +1,7 @@
|
|||||||
# Memory!
|
# Memory!
|
||||||
|
|
||||||
Tonight you are going to build the game called: [Memory](https://en.wikipedia.org/wiki/Concentration_(game)). We have provided you with a few starter files. You will look at the `index.html` to set up your physical board and cards, but write the code in your `app.js` file to get your game to work.
|
Today we are going to build the game Memory. Write all your code in app.js, but
|
||||||
|
look at index.html to get your bearings.
|
||||||
Take it one step at a time. Follow these instructions to help get you going.
|
|
||||||
|
|
||||||
|
|
||||||
### You will need
|
### You will need
|
||||||
|
|
||||||
@ -1,11 +1,70 @@
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
console.log('Loaded, bro');
|
console.log('loaded');
|
||||||
|
|
||||||
|
// Invoke your chain of functions and listeners within window.onload
|
||||||
|
// var button = document.getElementsByTagName('button');
|
||||||
|
// button.onclick(function(){
|
||||||
|
// start();
|
||||||
|
// })
|
||||||
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// USE THIS TO SHUFFLE YOUR NUMBERS
|
|
||||||
//+ Jonas Raoni Soares Silva
|
// USE THIS TO SHUFFLE YOUR ARRAYS
|
||||||
//@ http://jsfromhell.com/array/shuffle [v1.0]
|
//o=array
|
||||||
function shuffle(o){ //v1.0
|
var tiles = ['A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'E', 'E'];
|
||||||
|
function shuffle(o) {
|
||||||
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
|
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
|
||||||
return o;
|
return o;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function start(){
|
||||||
|
|
||||||
|
shuffle(tiles);
|
||||||
|
makeAndDisplayTiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeAndDisplayTiles(){
|
||||||
|
document.getElementById('game').innerHTML = "";
|
||||||
|
document.getElementById('info').innerHTML = "";
|
||||||
|
for(var i = 0; i<tiles.length;i++){
|
||||||
|
var tile = document.createElement('div');
|
||||||
|
tile.setAttribute('class', 'column');
|
||||||
|
tile.setAttribute('data-value',tiles[i]);
|
||||||
|
document.getElementById('game').appendChild(tile);
|
||||||
|
tile.onclick = function(){
|
||||||
|
makePlay(this);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// addEventsToTiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
// function addEventsToTiles(){
|
||||||
|
// var tile = document.getElementsByClassName('column');
|
||||||
|
// tile.onclick = makePlay(this);
|
||||||
|
// }
|
||||||
|
|
||||||
|
function makePlay(tile){
|
||||||
|
tile.innerHTML = tile.dataset.value;
|
||||||
|
tile.className += " found";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function processData(n) {
|
||||||
|
var result="";
|
||||||
|
for(var i = 1; i<=n; i++){
|
||||||
|
var spaces = i;
|
||||||
|
while(spaces <= n-1){
|
||||||
|
result+=" ";
|
||||||
|
spaces++;
|
||||||
|
}
|
||||||
|
var stairs = i;
|
||||||
|
while(stairs > 0){
|
||||||
|
result+='#';
|
||||||
|
stairs--;
|
||||||
|
}
|
||||||
|
result+='\n'
|
||||||
|
}
|
||||||
|
console.log(result);
|
||||||
|
}
|
||||||
Loading…
Reference in new issue