Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

10
Daniel Gagnon’s Final Daniel Gagnon’s Final Project Project Number Guessing Game Number Guessing Game Widget Widget By: Daniel Gagnon By: Daniel Gagnon

Transcript of Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Page 1: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Daniel Gagnon’s Final Daniel Gagnon’s Final ProjectProject

Number Guessing Game Number Guessing Game WidgetWidget

By: Daniel GagnonBy: Daniel Gagnon

Page 2: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Number Guessing Game Number Guessing Game WidgetWidget

• This is a Widget program that was created to be a This is a Widget program that was created to be a game. The program first picks a random number game. The program first picks a random number between 0 and 50. The player then tries to guess between 0 and 50. The player then tries to guess that number in the fewest number of tries. The that number in the fewest number of tries. The program gives the player hints every time a program gives the player hints every time a number is guessed. After the correct number is number is guessed. After the correct number is guessed, the program tells the player how many guessed, the program tells the player how many tries it took.tries it took.

Page 3: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Interesting parts of codeInteresting parts of code

• Random Number GeneratorRandom Number Generator

• var number = random(0,50);var number = random(0,50);

• This line of code creates a varaible “number” and the This line of code creates a varaible “number” and the actual random number. This code is important beacasuse it actual random number. This code is important beacasuse it is the most important part of the game. If there were no is the most important part of the game. If there were no random number the player would not have to guess to get random number the player would not have to guess to get the correct number.the correct number.

Page 4: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Interesting Code cont.Interesting Code cont.

• CounterCounter

• var counter;var counter;

counter=0;counter=0;

counter++counter++

• The first line of code creates a variable that will be used as a The first line of code creates a variable that will be used as a counter. The second line of code sets the counter to zero. The counter. The second line of code sets the counter to zero. The third line of code adds one to the counter every time the third line of code adds one to the counter every time the function is run. This code is important becasuse it lets the function is run. This code is important becasuse it lets the player of the game know how many tries it took them to player of the game know how many tries it took them to guess the correct number.guess the correct number.

Page 5: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Interesting Code cont.Interesting Code cont.

• Interworking of the GameInterworking of the Game

• function tryNumber(theNumber) {function tryNumber(theNumber) {if (the_number.data <number) alert("Guess Higher");if (the_number.data <number) alert("Guess Higher");else if (the_number.data > number) alert("Guess Lower");else if (the_number.data > number) alert("Guess Lower");}}

• This is part of the function that runs the game. The first This is part of the function that runs the game. The first line establishes the function and the name of the function. line establishes the function and the name of the function. The second line determines if the number the player The second line determines if the number the player guesses is less than the random number generated, while guesses is less than the random number generated, while the third line determines if the player guesses greater the third line determines if the player guesses greater than the random number. This function allows the than the random number. This function allows the program to tell the player if they need to guess a higher program to tell the player if they need to guess a higher or lower number.or lower number.

Page 6: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

What I LearnedWhat I Learned

• As the programmer of this game I learned that it is As the programmer of this game I learned that it is actually not too difficult to design a program and actually not too difficult to design a program and execute it as long as you have a drawn up plan. I execute it as long as you have a drawn up plan. I made a drawing of how I wanted the program to look made a drawing of how I wanted the program to look and work and then wrote it. This helped me a great and work and then wrote it. This helped me a great deal.deal.

• I first wrote this game to work on a website and not I first wrote this game to work on a website and not as a widget. This was a mistake. It is better to write as a widget. This was a mistake. It is better to write the program only once and not have to rewrite it and the program only once and not have to rewrite it and figure everything out twice.figure everything out twice.

• I also learned that a random number generator is a I also learned that a random number generator is a powerful tool and can be used for many applications. powerful tool and can be used for many applications.

Page 7: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

DifficultiesDifficulties

• One of the difficulties that I ran into while creating One of the difficulties that I ran into while creating this project was trying to create a function that helped this project was trying to create a function that helped the user determine if the number they guessed was the user determine if the number they guessed was too high or too low. I overcame this problem by trial too high or too low. I overcame this problem by trial and error. I tried different if, else if, and else and error. I tried different if, else if, and else statements until I figured out what worked and what statements until I figured out what worked and what didn’t.didn’t.

• Another difficulity I had was trying to change my Another difficulity I had was trying to change my original program that I wrote for this project into a original program that I wrote for this project into a widget. I found that even though widgets use widget. I found that even though widgets use JavaScript you cannot just cut and paste your code JavaScript you cannot just cut and paste your code into the widget. There is much more involved.into the widget. There is much more involved.

Page 8: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Great DiscoveriesGreat Discoveries

• I don’t feel that I made any real new great I don’t feel that I made any real new great discoveries for JavaScript or Widgets, but I do feel discoveries for JavaScript or Widgets, but I do feel that I discovered Random Number Generators by that I discovered Random Number Generators by myself. I don’t think we covered any random myself. I don’t think we covered any random numbers in class so I felt accomplishment when I numbers in class so I felt accomplishment when I got my random number generator to work got my random number generator to work correctly with my game.correctly with my game.

Page 9: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

ConclusionConclusion

• This project taught me a lot about programming. I This project taught me a lot about programming. I learned how to set a goal for what I wanted my learned how to set a goal for what I wanted my program to look like and do and I went and did it. program to look like and do and I went and did it. I found that trial and error in programming is I found that trial and error in programming is basically the only way to finalize a project to be basically the only way to finalize a project to be sure it works 100% correctly. This project was sure it works 100% correctly. This project was challenging and fun for me and I felt I learned a challenging and fun for me and I felt I learned a lot for my first programming class.lot for my first programming class.

Page 10: Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon.

Program and Slide Show Program and Slide Show Created by:Created by:

Daniel GagnonDaniel Gagnon