Programming games HTML/JavaScript basics Functions, events, forms

Slides:



Advertisements
Similar presentations
The Web Warrior Guide to Web Design Technologies
Advertisements

Programming games Classwork: Show Favorite Sites. Show coin toss. Review concepts. Crooked coin toss. Homework: Complete coin toss examples. Upload files.
Information Technology Center Hany Abdelwahab Computer Specialist.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Computer Science 103 Chapter 4 Advanced JavaScript.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Javascript and the Web Whys and Hows of Javascript.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
INTRODUCTION. What is HTML? HTML is a language for describing web pages. HTML stands for Hyper Text Markup Language HTML is not a programming language,
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript - A Web Script Language Fred Durao
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Creating Web Documents: JavaScript Continue with JavaScript Form check Dice (die) throw Questions for midterm Homework: Prepare for midterm. Complete project.
Programming games HTML/JavaScript basics Functions, events, forms Classwork: [Show favorite sites.] Coin toss. Homework: GET WEB SPACE. Complete coin toss.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Creating Web Documents catch-up JavaScript slide show tools redirection.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Creating Web Documents: JavaScript Ftp / file management: review Introduction to JavaScript Sources Homework: start review for midterm, work on Project.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Programming games Show work on site. Work on slide show. Timed event for bouncing ball. Homework: [Finish slide show and upload to site.] Acquire a short.
Tarik Booker CS 120 California State University, Los Angeles.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Build in Objects In JavaScript, almost "everything" is an object.
Unit 2 Technology Systems
HTML Basics.
Chapter 11 - JavaScript: Arrays
Programming games HTML/JavaScript basics Functions, events, forms
CHAPTER 10 JAVA SCRIPT.
Creating Databases Local storage. join & split
Learning to Program D is for Digital.
Web Development & Design Foundations with HTML5
Week 4: Introduction to Javascript
JavaScript is a programming language designed for Web pages.
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
Section 17.1 Section 17.2 Add an audio file using HTML
Web Development & Design Foundations with HTML5 7th Edition
JavaScript Functions.
Web Programming– UFCFB Lecture 17
Programming Games Computer science big ideas and Computer Science jargon: review of things we have used in examples. Show virtual dog Homework: [Catch.
Learning Objectives Apply JavaScript rules for functions, declarations, return values, function calls, scope of reference, and local/global variable reference.
JavaScript Functions B. Ramamurthy 11/22/2018.
Event Driven Programming & User Defined Functions
Of HTML, CSS and JavaScript
Integrating JavaScript and HTML
Basic HTML and Embed Codes
Javascript Game Assessment
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Chapter 7 Event-Driven Pages
JavaScript is a scripting language designed for Web pages by Netscape.
JavaScript.
Web Programming and Design
Week 5: Recap and Portfolio Site
Web Programming and Design
Web Programming and Design
Introduction to Web programming
Presentation transcript:

Programming games HTML/JavaScript basics Functions, events, forms Classwork: Favorite Sites. Coin toss. Homework: GET WEB SPACE. Complete crooked coin toss. HTML basics first

Recap on shoe tying Directions for sequence of operations Included 'event' related actions: do this until this situation is true Usual form is: when this event happens, do this. The pulling of the laces was keep going until something happens Double loop (bunny ears) method made two overhand knots Task definition versus language for task

Icons and styles Things can be inside things! The contents of an a element can be… an img element. This produces a clickable picture. A style is defined to apply to specific element types. Styles also can apply to all elements of a designed class or an element with a specific id. More on this later.

secondtest.html <html> <head><title>Second test</title> <style> article { font-size:20px; display:block; } img {display:block;} </style> <script> document.write("<i>"+Date()+"</i>"); </script> </head> <body> <article>This is the Meyer family origami page. <a href="http://faculty.purchase.edu/jeanine.meyer/origami"><img src="bird.gif"/></a> </article> </body> </html>

Notice bigger letters and the line. Notice box around the bird!

Lessons Notice patterns Things inside of things…. Practice pop research quiz: look up CSS font-family and see how to specify fonts. All fonts are not on all computers, so you specify your first choice, second choice, then type (serif, monospace)

Class work Produce an HTML file that presents 3 (favorite) websites writes out the date at the top Title is your name plus 'Favorite Sites' Describes 'favorite sites', with text and an image from the site, linking to the site. Enclose each description in an article element.

Web publishing space CTS provides web space for all students. Do sign up for it! You will be required to upload projects—publish them—on the web.

Preparation for…coin toss Image change Variables Math functions Math.random() if statement Function definitions and Function calls

Image change Image tag (and other tags) can have names: <img name="coin" src="blank.gif"> Your code can change the image being displayed by referring to the src attribute of the img element of a given name: document.coin.src = "head.gif" You may be able to leave off the window in window.document….

Variables Variable is a programming construct for associating a name (possibly a place in memory) with a value. Your code then uses the name as it would the value. JavaScript and ActionScript have the var statement for setting up a variable. IT IS NOT ALWAYS NECESSARY to do this before using a variable, but is a good idea. var size = 25; var classname = "Programming Games"; var ta = "Kathryn"; A variable can be referenced in code and changed by code. document.write("The class is " + classname + " and the TA is "+ ta); size = size + 1; SAME AS size++;

Array variables Variables hold different types of data int, number, string, Boolean… ALSO: arrays var tas = ["Kathryn", "Luke"]; To get at individual components, use indexing. The first index is 0!!! tas[0] is "Kathryn" tas[1] is "Luke"

Note [ordinary] arrays require the programmer to put the items in order. Must make sure that that order doesn't influence anything it shouldn't…. Think about this in rock, paper, scissors Some languages do have associative arrays: indexing by keys, not numbers. Some languages allow programmer to specify range of numbers SETL is a language that has unordered sets as primitive data type.

Variables Variables can be outside of any function, within the script tag. The scope of these variables is global. They can be referenced and changed everywhere. Variables within, local to, a function go away when the function ends. Variables are stored 'in memory' and go away when you exit the function or leave the page. Variables are reinitialized when you refresh/reload a page. See in coin toss, the return false makes sure the page is not refreshed/reloaded.

Math functions JavaScript and ActionScript, etc. provide many standard math functions. This is formally done as methods of the (single) Math object. We will use Math.sin() and Math.cos() for the cannonball game (ballistics simulation). Many games require use of Math.random() This returns a (fraction/decimal) value from 0 up to, but not including 1.

If statement Example of conditional statement. Two forms if (condition) { statements } Or else { The indenting is NOT required, but is a good idea to help you keep track of what is going on.

example var toss = Math.random(); if (toss>.5) { alert("greater than .5"); } else {alert("not greater than .5"); }

example var toss = Math.random(); if (toss>.5) { alert("greater than .5"); } else {alert("not greater than .5"); } At this point, toss will hold a number (fraction). Note: look ahead: the trace function will do a similar task as alert in ActionScript/Flash. Writes out string in box string is string (sequence) of symbols, such as a message

So in coin toss var toss = Math.random(); if (toss>=.5) { document.coin.src = "head.gif"; } else { document.coin.src="tail.gif"; } var statement sets up the variable named toss AND immediately gives it a value. The var statements are not required, but a good practice. This is called a variable declaration. Some languages require them.

Function definition You can define your own functions, to be used by your code called 'user-defined functions', but this may be confusing because you are the developer/programming and not the end user. I prefer 'player' to user. Function definitions generally are in the <script> </script> element in the <head> </head>. Calls (invocations) of functions in tags in the body or in other functions (or in this function, but more on that much later).

Analogy to function definition From now on, when I say 'check the schedule', I mean [go to a computer connected to the Web. Invoke a browser. Go to my website: http://faculty.purchase.edu/jeanine.meyer Click on link to Lectures, materials. Click on Schedule under Programming Games

JavaScript function definition function functionname (args if there are any) { statements } </script> Outline.

Function call Set up to be response to the submit event—clicking on a submit button for a form <form action="" onSubmit="return toss();"> <input type="submit" value="TOSS"> </form> The return may not be necessary. Within the definition of the toss function will be a return statement.

Example: changepicture script element holds 3 variables and one function definition original, next, current and change body holds img and form img is named place, src (initially) the same value as original form element is what produces the button that calls the change() use onSubmit

var original = "bird.gif"; var next ="frog.gif"; <html><head><script> var original = "bird.gif"; var next ="frog.gif"; var current = "bird.gif"; function change() { if (current==original) { current = next; document.place.src = next; } else { current = original; document.place.src = original;} return false; } </script> </head> <body> <img name="place" src="bird.gif"/> <form action="" onSubmit="return change();"> <input type="submit" value="Change"> </form> </body> </html> Notice == for the checking for equality operation Squeezed to fit on a chart.

form Can use form input values to output (display) information to player Will show more of this

form <script> … f.ans.value= ???? </script> <body> <form action="" name="f" onSubmit="return toss();"> <input type="text" name="ans"> <input type="submit" value="TOSS"> </form> </body>

onsubmit When form submit button is pressed, invoke the toss() function and return to the system whatever value it returns. Functions can return/produce values A return value of false (the Boolean value false) means the html page will not be refreshed—changed back to the original.

Other Function calls In <a> tag as value of href <a href="javascript:fun(a, b);"> Call fun </a> In <a> tag as value of onClick, onMouseover or onMouseOut <a href="" onMouseover="fun(a,b);" > Set up to be called after time interval. This statement will be somewhere in the code, perhaps within another function. tid = setInterval("moveit(dx, dy)",500); We will use these later.

Classwork Find images for coin toss Read coin toss tutorial. The head of coin, tail of coin, and a blank or question mark. NOTE: this is not the main point of the assignment, so don't spend too much time on it. Read coin toss tutorial. Prepare coin toss.

Next How to make this a crooked/biased/weighted coin? Prepare for next class.

Web space You need an account on the purchase student server for this course to upload work!!! Go to http://students.purchase.edu and follow directions.