RSS

Outlining and early steps in coding mastermind

29 Jun

The only language that I have an even decent grasp on right now is javascript. So, even though I know I’ll have to redo most of my work in order to get this project into XCode, I’m starting there.

 

My first thought was to create an outline of how I think the program should function.

 

I’m not sure what will change over time, but to start I had this:

 

//gets the number of digits used

var code = function(){

console.log(“***code function reached***”);

};

 

//gets numerals to be used in code

var numbers = function(){

console.log(“***numbers function reached***”);

};

 

//sets up an array of numbers that will be the secret code

// code is the number of digits, number is the integers used for each digit

setSecretCode = function(code,numbers){

console.log(“***reached setSecretCode function***”);

};

 

//accepts guess from user and parses it into an array of ‘code’ length

acceptGuess = function(code,numbers){

    console.log(“***acceptGuess function reached***”);

};  

 

var compareGuess = function(){

    console.log(“***compareGuess function reached***”);

};

 

var showResult = function(){

    console.log(“***showResult function reached***”);

    exitShowResultLoop = true;

};

 

 

var exitShowResultLoop = false;

//computer prompts users for parameters to build secret code

var enteredCode = code(); // brings the variable  enteredCode out of the function

console.log(enteredCode); //checking variable

var enteredNumber = numbers(); // brings the variable enteredNumber out of the function

 console.log(enteredNumber); //checking variable

 

//computer sets secret code

var secret = setSecretCode(enteredCode,enteredNumber);

 

//printout of array for debugging

console.log(“secret code is: “+ secret);

 

//play the game using a while loop to loop until correct guess is made

while (exitShowResultLoop === false){

    var guessArray = acceptGuess(enteredCode, enteredNumber);

    console.log(“guess is: “+guessArray);

    compareGuess();

    showResult(); //contains an exit clause

}

console.log(“You’ve done it!!! Congratulations!!”);

 

 Really, this is just a list of functions and function calls that I want to build out. I think that if I can write each of these properly, I should have a functioning game. For starters, I have a ton of console.log()’s littered everywhere just to make sure that the program is going to each function in turn. Once I complete a section, I comment them out or completely delete then and replace them with notes about how things work.

Another important thing I learned was that it’s easiest to look at this in chunks. set variables myself and send them into the functions so they could be made independently. I’m sure this is not worth mentioning to anyone who has done any programming, but to someone like me it was an epiphany.

 

More later as I flesh things out….

 

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: