Wednesday, March 9, 2016

Day 203: FCC, Continuing With Final Project for Front End Web Dev Certificate, the "Simon Game"

All right, it's a new day, time to keep moving forward on this project so I can finish it ASAP and get back to Harvard's CS50 class as well as!

I got quite a bit done yesterday.  The first thing I'll do today is create a mechanism for comparing the two arrays that hold the selections (the computer's and the player's).

All right, I finished that function:

function testMatch(arrayComputer, arrayPlayer) {
  for (var i = 0; i < arrayComputer.length; i++) {
    if (arrayComputer[i] !== arrayPlayer[i]){
      return false;  
    }
  }
  return true;

}

So now I need to figure out a way to make the computer go once, then twice, then three times, and so on.  I figured it out!  Well, partially anyhow, this code makes whatever you put inside of it wait one before running:

setTimeout(function(){ alert("Hello"); }, 3000);

In the case above, the alert would rund 3 seconds after it normally would.  So, this function:

function testMatch(arrayComputer, arrayPlayer) {
  for (var i = 0; i < arrayComputer.length; i++) {
    if (arrayComputer[i] !== arrayPlayer[i]){
      return false;  
    }
  }
  return true;

}

Creates an array with 20 items in it comprised of the id's for each of the boxes/selections.  
I'm working on making a for loop delay iterations.  I've put a little over 7 hours into the project today.  Hopefully I can complete it tomorrow.  Here's my total JavaScript notes for the day:

$(document).ready(function() {
  
createSequence20();
  
$(".boxes" ).click(function() {
  
  $("#counter").text(counter);
  if (counter === 20) {
    alert("Congratulations, you win!");
  }
  
  switch (this.attributes[1].value) {
    case "boxGreen":
      audioGreen.play();
      break;
    case "boxRed":
      audioRed.play();
      break;
    case "boxYellow":
      audioYellow.play();
      break;
    case "boxBlue":
      audioBlue.play();
      break;        
  }
  
  $(this).animate({
    opacity: 1,
  }, 10, function() {
    // Animation complete.
  $(this).animate({
    opacity: .4,
  }, 500, function() {});
  });
  
  arrayPlayer.push("#" + this.attributes[1].value);
  if (testMatch(goalPattern, arrayPlayer) === true) {
    console.log("correct");
    counter = counter + 1;
    $("#counter").text(counter);
    //runSequence();
    loop();  
  }  // End if statement that checks if player's selection matched the goalPattern array element.

  console.log(arrayPlayer);
  console.log(testMatch(goalPattern, arrayPlayer));
  
});  //  Ends player click event
  
  // The code below begins the random sequence, in other words, the computer's turn.
$("#start").click(function(){
  counter = counter + 1;
  $("#counter").text(counter);
  startSequence();
});
   
  
function startSequence() {
  
  current = goalPattern[0]
  switch (current) {
    case "#boxGreen":
      audioGreen.play();
      break;
    case "#boxRed":
      audioRed.play();
      break;
    case "#boxYellow":
      audioYellow.play();
      break;
    case "#boxBlue":
      audioBlue.play();
      break;
  }
  
  $(current).animate({
    opacity: 1,
  }, 250, function() {
    // Animation complete.
  $(current).animate({
    opacity: .4,
  }, 250, function() {});
  });
    
} // End of start function
    
 // Reset Game
 $("#reset").click(function(){
   resetGame();
 }); 
  
  
});  //  Closes jQuery wrapper

var audioGreen = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
var audioRed = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
var audioBlue = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
var audioYellow = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");
var counter = 0;
var arrayIds = ["#boxGreen", "#boxRed", "#boxBlue", "#boxYellow"];
var arrayPlayer = [];
var randomSeq;
var goalPattern = [];

function randomNum0to3() {
  return Math.floor(Math.random() * 4);
}

function createSequence20() {
  for (var i = 0; i < 20; i++) {
    goalPattern.push(arrayIds[randomNum0to3()]);
  }
  console.log(goalPattern);
}

function testMatch(goalPattern, arrayPlayer) {
  for (var i = 0; i < arrayPlayer.length; i++) {
    if (goalPattern[i] !== arrayPlayer[i]){
      return false;  
    }
  }
  return true;
}

function resetGame() {
  arrayPlayer = [];
  goalPattern =[];
  createSequence20();
  counter = 0;
  $("#counter").text(counter);
}


(function loop(i) { 
  setTimeout(function() {
    
    $(goalPattern[i - 1]).animate({
    opacity: 1,
  }, 250, function() {
    // Animation complete.
  $(goalPattern[i - 1]).animate({
    opacity: .4,
  }, 250, function() {});
  });
    
    if (--i) loop(i); // iteration counter
  }, 1000) // delay
}) (arrayPlayer.length + 5);// iterations count


/*function runSequence() {
   
 for (var i = 0; i < counter; i++) {
    (function(i){
  setTimeout(function(){ 
      
  $(goalPattern[i]).animate({
    opacity: 1,
  }, 250, function() {
    // Animation complete.
  $(goalPattern[i]).animate({
    opacity: .4,
  }, 250, function() {});
  });
      
  }, 1000); 
    }(i));
    
  }  // Ends for loop
  // Ends setTimeout  
}  // Ends runSequence
*/






/*  
setTimeout(function(){ 
    
  for(var i = 0; i < arrayPlayer.length + 1; i++) { 
    
  setTimeout(function(){ 
    
  console.log("for loop iteration");
  var current = goalPattern[i - 1]
  
   }, 250); // Closes setTimeout inside of for loop 
    
  }   // End of for loop that runs as many times as the counter.
    
  }, 250); // End of setTimeout below startSequence
*/

/*
 setTimeout(function(){ 
       
    }, 500);

*/

And a screenshot:




It's coming along.  

All right, time for bed.

SUMMARY OF CODING SKILLS 

Books:                                                                                               Status
"Head First HTML and CSS," by E. Robson & E. Freeman                      Complete
"A Smarter Way to Learn JavaScript," by Mark Myers                          Complete
"HTML and CSS," by Jon Duckett                                                        Complete
"JavaScript and JQuery," by Jon Duckett                                            Complete
Team Treehouse (Front End Web Dev Track Complete):                    Status
How to Make a Website                                                                     Complete
HTML                                                                                                Complete
HTML Forms                                                                                      Complete
HTML Tables                                                                                     Complete
HTML Video and Audio                                                                       Complete
CSS Foundations                                                                                Complete
CSS Basics                                                                                         Complete
CSS Layout Techniques                                                                      Complete
CSS Layout Basics                                                                              Complete
CSS Selectors                                                                                     Complete
Responsive Layouts                                                                            Complete
CSS Flexbox Layout                                                                            Complete
Git Basics                                                                                          Complete
Console Foundations                                                                          Complete
Introduction to Programming                                                              Complete
JavaScript Basics                                                                               Complete
JavaScript Loops, Arrays, & Objects                                                   Complete
AJAX Basics                                                                                       Complete
JQuery Basics                                                                                    Complete
Interactive Web pages with JavaScript                                               Complete
Object-Oriented JavaScript                                                                Complete 
Accessibility                                                                                      Complete
Website Optimization                                                                        Complete
Front End Performance Optimization                                                  Complete
Aesthetic Foundations                                                                        Complete                 
Design Foundations                                                                            Complete  
Adobe Photoshop Foundations                                                            Complete
Adobe Illustrator Foundations                                                      66% Complete

Other Courses:                                                                                     Status
HTML and CSS (Codecademy)                                                               Complete
Introduction to Web Dev (The Odin Project)                                         Complete
Web Dev 101 (The Odin Project)                                                    33% Complete

Free Code Camp (FCC)                                                                           Status
1. Get Started with Free Code Camp                                                     Complete
2. HTML5 and CSS                                                                                 Complete
3. Responsive Design with Bootstrap                                                      Complete
4. Gear up for Success                                                                          Complete
5. jQuery                                                                                             Complete

6. Basic Front End Development Projects                                              Complete
7. Basic JavaScript                                                                                Complete
8. Object Oriented and Functional Programming                                    Complete
9. Basic Algorithm Scripting                                                                   Complete

10. JSON API's and Ajax                                                                         Complete
11. Intermediate Front End Development Projects                                  Complete
12. Intermediate Algorithm Scripting                                                     Complete
13. Advanced Front End Development Projects                                       On 6 of 6
14. Claim Your Front End Development Certificate
15. Automated Testing and Debugging
16. 
Node.js and Express.js
17. Git
18. MongoDB
19. API Projects
20. Dynamic Web Application Projects
21. Claim Your Back End Development Certificate

Harvard CS50: Intro to Comp Sci                                                             Status
12 Week Course (Plus Week 0), Pre-Work for UT Boot Camp                On Week 0 of 12

The Coding Boot Camp at UT Austin                                              Status (starts 4/19/2016)
Week 1-6: Mastering the Browser (HTML, CSS, JavaScript, JQuery) 
Week 7-10: API & JSON (RESTful API"s, parsing JSON, AJAX)
Week 11-14: Server Side (Node.js, MySQL, MongoDB)
Week 15-18: PHP (WordPress, CodeIgniter, Laravel) 
Week 18-21: Full Stack Coding
Week 22-24: Final Project

CodePen: http://codepen.io/Adancode/
GitHub: https://github.com/Adancode
LinkedIn: https://www.linkedin.com/in/adamcamacho1
Team Treehouse: https://teamtreehouse.com/adamcamacho
Free Code Camp: http://www.freecodecamp.com/adancode

Hours Spent Coding Today: 7.5
Total Hours Coding: 1,059

No comments:

Post a Comment