110 likes | 123 Views
Programming Games. Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show. 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.
E N D
Programming Games Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show.
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, sayvar 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 displaydocument.f.bank.value = bankr; // conversion done
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 oncetid = setInterval(finish,2000); clearInterval(tid);
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.
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?
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.
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
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 • http://faculty.purchase.edu/jeanine.meyergoes to my index.html file. • Your index.html files can be simple. Use <br> or <p> and </p> or <ol><li> </li> </ol> etc.
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>
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!
Homework • [finish dice game] • Continue uploading projects to your site • Read tutorial, examine code, acquire image files, and complete slide show.