Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Games Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show.

Similar presentations


Presentation on theme: "Programming Games Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show."— Presentation transcript:

1 Programming Games Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show.

2 Dice game additions Score keeping for dice game can be done using the notion of a bankroll, kept as internal variable and displayed as part of form. Initial starting amount, say var bankr = 100; On every first move: if (bankr>=10) {bankr -= 10;} else { On every win: bankr += 20; NOTE: nothing happens when there is a loss. Also need to display document.f.bank.value = bankr; // conversion done

3 Timed events JavaScript provides functions for setting up timed events
setInterval ('moveit(dx,dy)',500); tid = setInterval('change()',800); setInterval(change,800); setTimeout(finish,2000); //just happens once tid = setInterval(finish,2000); clearInterval(tid);

4 Timed events The coding is different, but the underlying concept is the same as other events set up handling for event: do something, generally invoke a function, when something happens write the event handler function event can be stopped, for the timing event, that means a call to clearInterval using the value set by the call to setInterval or setTimeout.

5 Exercises Set up a timed event to be a call to "stopgame();" to happen once in 10 seconds? one and one half seconds? What do you think stopgame is? Set up timed events to be a call to "moveit(dx,dy);" to happen 10 times/second until your code stops it?

6 Slide show Use form buttons to start and stop the slide show.
Starting the slide show is done by a function that contains a call to setInterval. Stopping the slide show is done by a function that contains a call to clearInterval. The change function advances the slide show using a variable sn and then incrementing sn. The sn variable is reset back to zero when it reaches the end—pointing past the end of the array holding the names of the slide image files.

7 Reprise: Your server site
students.purchase.edu Use what is termed an ftp (file transfer protocol) program to upload and download files. Filezilla, others If you are or anticipate taking other computer classes, make a folder: games or pg

8 Server site, cont. Create an index.html file
The action by the browser to an incomplete address will be to look for an index.html file goes to my index.html file. Your index.html files can be simple. Use <br> or <p> and </p> or <ol><li> </li> </ol> etc.

9 index.html <html><head><title>Jeanine's games </title></head> <body> <ul> <li><a href="favoritesites.html">My favorite sites </a> </li> <li><a href="cointoss.html">Coin toss</a></li> … </ul> </body> </html>

10 Upload index.html all files for each of your games
Make sure they are in the correct folder. NOTE: you don't use the web in the address. TEST to see if you get to the index file and then if the link to each game works and the game works!

11 Homework [finish dice game] Continue uploading projects to your site
Read tutorial, examine code, acquire image files, and complete slide show.


Download ppt "Programming Games Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show."

Similar presentations


Ads by Google