Programming games HTML/JavaScript basics Functions, events, forms Classwork: [Show favorite sites.] Coin toss. Homework: GET WEB SPACE. Complete coin toss.

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.
Page 1 of 26 Javascript/Jscript Ch 7,8,9,10 Vadim Parizher Computer Science Department California State University, Northridge Spring 2003 Slides from.
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
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.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Python quick start guide
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Scripting Languages.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript Part 1.
JavaScript Lecture 6 Rachel A Ober
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Programming games Reprise: coin toss on canvas. Dice game rules. Global and local variables. Homework: [Catch up. Upload projects, including index.html.]
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.
Homework: New coin toss. [Start dice game.]
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
How to Create a Videogame By: Connor McCann. Java Java is one of many programming languages Java is used to run web browsers and most PC video games I.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Programming games Show shaking screen, quiz show. Calculations Homework: (Finish basic Javascript Projects) Make proposal. Work on project.
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.
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved. 2 Revised by Dr. T. Tran for CSI3140.
Creating Web Documents catch-up JavaScript slide show tools redirection.
JavaScript, Fourth Edition
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
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.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Creating Web Documents: JavaScript Ftp / file management: review Introduction to JavaScript Sources Homework: start review for midterm, work on Project.
Language Find the latest version of this document at
Understanding JavaScript and Coding Essentials Lesson 8.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
REEM ALMOTIRI Information Technology Department Majmaah University.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Programming games HTML/JavaScript basics Functions, events, forms
Programming games HTML/JavaScript basics Functions, events, forms
JavaScript Functions.
Programming Games Computer science big ideas and Computer Science jargon: review of things we have used in examples. Show virtual dog Homework: [Catch.
Event Driven Programming & User Defined Functions
Javascript Game Assessment
Tutorial 10: Programming with javascript
Programming games Share your plans for your virtual something.
Web Programming and Design
Intro to Programming (in JavaScript)
Presentation transcript:

Programming games HTML/JavaScript basics Functions, events, forms Classwork: [Show favorite sites.] Coin toss. Homework: GET WEB SPACE. Complete coin toss.

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

Recap What are the parts of an html document?

template Sites article {display:block; ….} My sites …. …

Fonts How do you use CSS to specify font for a specific element type, such as article? Look it up! Terms could be html5 font Note: I want the formatting in the element, not in the body.

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: HTML tags have attributes. –name and src are each attributes. 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"

So… if my/our code determines that a head of a coin should be shown, and the img element has the name coin and the name of the image files are "head.gif" and "tail.gif", how do we write the code to make sure the img element is showing a tail?

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. Values are specific datatypes: integers, numbers, strings of characters, Booleans, other things JavaScript has 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. The term for this is declaring a variable. This is required in many programming languages, for example, Processing. var size = 25; var classname = "Programming Games"; var ta = "Skylar"; 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… –Arrays are a type of variable that holds an ordered set of values var tas = ["Skylar", "Allen"]; To get at individual components, use indexing. The first index is 0 tas[0] is " Skylar" tas[1] is " Allen"

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…. –See my implementations of rock, paper, scissors JavaScript, some other languages, also have associative arrays: indexing by keys, not numbers. (Python calls these dictionaries) Some languages allow programmer to specify the range of numbers. SETL is a language that has unordered sets as primitive data type. Haskell is a language that includes ways to specify infinite sets.

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. MORE ON THIS LATER: when we do the dice game (craps) 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, Objective-C, Processing, etc. provide many standard math functions as part of the language. Javascript does this using methods of the (single) Math class. 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 if (condition) { statements } else { statements }

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). 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"; }

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. –I call them programmer-defined functions. Function definitions generally are in the element in the. 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: Click on Current. Click on Schedule under Programming Games

JavaScript function definition function functionname (args if there are any) { statements }

Function call Functions can be called / invoked / executed in different ways. One way is the result of an event set up in a tag Flip coin!

Aside There is a tutorial on coin toss. You now have heard about different features/constructs that are used. The coin toss puts them together. In your notebook, make note of the terms function, array, variable. These are common and important terms in computer programming jargon. Look them up. Read multiple sources.

Classwork Be ready to show your favorite sites. Acquire (find on-line) image files of coin faces. Look at newcointoss.doc tutorial (follow link from the currentcourses.html page) and create a simple coin toss application.

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"; var current = "bird.gif"; function change() { if (current==original) { current = next; document.place.src = next; } else { current = original; document.place.src = original;} return false; } Notice == for the checking for equality operation

form Can use form input values to –present button to player –output (display) information to player –as well as input values Will show more of this

form … f.ans.value= ????

More on functions Functions in programming are ways to store code for later use. This includes storing code to be used (re-used) more than one time. They also can make code easier to understand. A function in JavaScript has a function. –The first use of function (italic and bold) is JavaScript jargon. The second use is English. Programming languages have constructions like functions. –For example, I'm learning Max, a language used for music and other things. It has encapsulations and abstractions.

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 tag as value of href Call fun In tag as value of onClick, onMouseover or onMouseOut 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);

HTML5 feature button as a new element type Use google to look up how to write a button

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 and follow directions.

Homework Introduce yourself on moodle if you haven’t done so –Respond to other posts Get web space Use the web to find definitions of –function –variable –object –class Check out books on reserve in Library Do coin toss